Nginx https error - nginx

I´m trying to setup nginx HTTPS on my host, but gets a error:
nginx: [emerg] "location" directive is not allowed here in /etc/nginx/conf.d/default.conf:7
nginx: configuration file /etc/nginx/nginx.conf test failed
Conf:
server {
listen 443 ssl;
server_name quickseed.me;
ssl_certificate /etc/letsencrypt/live/quickseed.me/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/quickseed.me/privkey.pem;
}
root /var/www/html/;
index index.php index.html index.htm index.nginx-debian.html;
location /phpmyadmin {
root /usr/share/;
index index.php;
try_files $uri $uri/ =404;
location ~ ^/phpmyadmin/(doc|sql|setup)/ {
deny all;
}
location ~ /phpmyadmin/(.+\.php)$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
Does anybody have any idea on how to fix this issue?

You should put location under a server directive. Try this code.
server {
listen 443 ssl;
server_name quickseed.me;
ssl_certificate /etc/letsencrypt/live/quickseed.me/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/quickseed.me/privkey.pem;
root /var/www/html/;
index index.php index.html index.htm index.nginx-debian.html;
location /phpmyadmin {
root /usr/share/;
index index.php;
try_files $uri $uri/ =404;
}
location ~ ^/phpmyadmin/(doc|sql|setup)/ {
deny all;
}
location ~ /phpmyadmin/(.+\.php)$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Hope it helps.

Related

Slim 4 Error 404 not found on nginx web server

Please help me, I want to move the project rest api (Slim 4 use Design Pattern) from apache to nginx, but I haven't found a solution to this problem, how to convert .htaccess to nginx server configuration, the error I found is always 404 (Slim / Middleware / RoutingMiddleware.php)
thank you for your help
this server config nginx
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.php index.htm index.nginx-debian.html;
autoindex off;
server_name _;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
}
location /FjbBaseApi {
index index.php index.html index.htm;
try_files $uri $uri/ /FjbBaseApi/public/index.php;
rewrite ^/$ /public/ break;
rewrite ^(.*)$ /public/$1 break;
}
location ~ /\.ht {
deny all;
}
}

Why nginx location directive doesn't work?

Salut! I'm learning nginx location directives. Now I faced a trouble:
server {
listen 80;
# server_name 127.0.0.1 localhost;
root /usr/share/nginx/html;
index index.php index.html index.htm index.nginx-debian.html;
location /rukovoditel/ {
index index.php index.html index.htm index.nginx-debian.html;
}
# location / {
# try_files $uri $uri/ =404;
# }
location ~ \.php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
This default.conf doesn't work correctly. When I go to 127.0.0.1/rukovoditel, I get an errror - connection refused.
But following default.conf works correctly!
server {
listen 80;
root /usr/share/nginx/html/rukovoditel;
index index.php index.html index.htm index.nginx-debian.html;
# location / {
# try_files $uri $uri/ =404;
# }
location ~ \.php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
Nginx service is running. -t output is correct.
Thanks for help!)

Nginx display just the Welcome page

I just set the nginx for a subdomain and even so I still get just the Welcome page.
Here is the code I set on nginx sites-available
server {
listen 80;
server_name sub.domain.ro;
rewrite ^ https://sub.domain.ro$request_uri? permanent;
}
server {
listen 443 ssl http2;
# ssl_certificate /etc/letsencrypt/live/testsite.com/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/testsite.com/privkey.pem;
# ssl_stapling on;
server_name sub.domain.ro;
root /var/www/sub.domain.ro;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Please let me know what I did wrong or what I forget here.

trouble with two locations in nginx config

I have 2 links: myserver.org and myserver.org/support
I need first link follow to /var/www/myserver.org and second to /var/www/support
My config now:
first file & link
server {
listen 80 default_server;
server_name groupmanager.org;
charset utf-8;
root /var/www/groupmanager.org;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
access_log /var/log/nginx/groupmanager.org_access.log;
error_log /var/log/nginx/groupmanager.org_error.log;
include /etc/nginx/templates/php-fpm.conf;
}
server {
listen 80;
server_name www.groupmanager.org;
rewrite ^(.*) http://groupmanager.org$1 permanent;
}
Second file & link:
server {
listen 80;
server_name 163.172.88.31/support;
charset utf-8;
root /var/www/support;
index index.php;
access_log /var/log/nginx/support_access.log;
error_log /var/log/nginx/support_error.log;
include /etc/nginx/templates/php-fpm.conf;
}
server {
listen 80;
server_name www.163.172.88.31/support;
rewrite ^(.*) http://163.172.88.31/support$1 permanent;
}
php-fpm.conf
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
location ~* \.(gif|jpeg|jpg|txt|png|tif|tiff|ico|jng|bmp|doc|pdf|rtf|xls|ppt|rar|rpm|swf|zip|bin|exe|dll|deb|cur)$ {
expires 168h;
}
location ~* \.(css|js)$ {
expires 180m;
}
First link works fine, second - no. I see '403 Forbidden'
What is not rigth?
Permissions for folders are the same, I think, they are right.
For both /var/www/myserver.org and /var/www/support you have to make two separate nginx config file with two different roots and server names .
besides , if you just want to show two links you can setup nginx for one and link the second one with just an internal link ( if they are in the same page)
Try like this:
include /etc/nginx/default.d/*.conf;
server {
listen 80 default_server;
server_name myserver.org;
charset utf-8;
root /var/www/myserver.org;
index index.php;
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
in /etc/nginx/default.d/ directory , create a .config file test.config:
location myserver.org {
proxy_pass /myserver.org;
}
location myserver.org/support {
proxy_pass /var/www/support;
}
This works:
groupmanager.org.conf
server {
listen 80 default_server;
server_name groupmanager.org;
charset utf-8;
root /var/www/groupmanager.org;
index index.php;
location /support/ {
alias /var/www/support/;
index index.php;
access_log /var/log/nginx/support_access.log;
error_log /var/log/nginx/support_error.log;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
}
}
access_log /var/log/nginx/groupmanager.org_access.log;
error_log /var/log/nginx/groupmanager.org_error.log;
include /etc/nginx/templates/php-fpm.conf;
}
server {
listen 80;
server_name www.groupmanager.org;
rewrite ^(.*) http://groupmanager.org$1 permanent;
}
php-fpm.conf
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
location ~* \.(gif|jpeg|jpg|txt|png|tif|tiff|ico|jng|bmp|doc|pdf|rtf|xls|ppt|rar|rpm|swf|zip|bin|exe|dll|deb|cur)$ {
expires 168h;
}
location ~* \.(css|js)$ {
expires 180m;
}

How can I run two standalone applications in one domain?

I have two apps... wordpress and WHMCS (a billing app)
example.com is wordpress.
example.com/portal to be WHMCS.
On the nginx server here is how I have my folders
/example.com
|_ /wordpress
|_ /whmcs
root is wordpress, but when someone goes to /portal I want the root to be /whmcs instead.
I've tried both root and alias. I either get 404 or 403 forbidden.
Here is my current example.conf file
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 80;
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/ssl.crt;
ssl_certificate_key /etc/nginx/ssl.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'AES128+EECDH:AES128+EDH';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
root /usr/share/nginx/example/wordpress;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ^~ /portal/index.php {
autoindex on;
alias /usr/share/nginx/example/portal;
}
}
The solution is not to share the php location.
server {
listen 80;
server_name example.com;
root /usr/share/nginx/example;
location / {
root /usr/share/nginx/example/wordpress;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; }
}
location /portal {
error_page 404 = #whmcs; }
location #whmcs {
rewrite ^(.*)$ /portal/index.php last;
root /usr/share/nginx/example/portal;
try_files $uri $uri/ /index.php?$query_string; }
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; }
}

Resources