I have a working WordPress installation on an Apache server and wanted to migrate to an NGINX server on a VPS. I've copied all the files, set up the MSQL connection, etc. and everything seems to work fine except the published articles, which all give 404 errors. The admin area works fine, with no apparent problems.
The virtual server configuration is:
server {
if ($host = www.xxx.es) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name xxx.es www.xxx.es;
return 301 https://www.xxx.es$request_uri;}
server {
server_name xxx.es www.xxx.es;
root /home/www/xxx.es/html/;
index index.php;
#listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.xxx.es/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.xxx.es/privkey.pem; # managed byCertbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {return 404;}
fastcgi_param HTTP_PROXY "";
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
I have tried the solutions of other questions without success. Thanks for the help
Try to change your part:
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {return 404;}
fastcgi_param HTTP_PROXY "";
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
to this one:
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\. {
deny all;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
Related
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.
I currently have Rainloop working with mail.mydomain.com without issue. Now I want to install zpush and put rainloop as a alias, ex: mail.mydomain.com/rainloop and leave zpush as mail.mydomain.com (for the auto discovery). This is what I have so far
server {
server_name mail.mydomain.com;
root /var/www/zpush;
access_log /var/www/rainloop/logs/access.log;
error_log /var/www/rainloop/logs/error.log;
index index.php;
location / {
try_files $uri /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_index index.php;
# fastcgi_param HTTPS on;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_keep_conn on;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Z-Push Ping command will be alive for 470s, but be safe
fastcgi_read_timeout 630;
}
location ~ /\.ht {
deny all;
}
location ^~ /data {
deny all;
}
location /Microsoft-Server-ActiveSync {
rewrite ^(.*)$ /index.php last;
}
location /rainloop {
alias /var/www/rainloop/;
index index.php;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mail.mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mail.mydomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
ssl_trusted_certificate /etc/letsencrypt/live/mail.mydomain.com/chain.pem; # managed by Certbot
ssl_stapling on; # managed by Certbot
ssl_stapling_verify on; # managed by Certbot
}
Not sure what I'm doing wrong or maybe I'm missing something? Keep getting the the 403
SOLVED IT: needed to create a symbolic link
ln -s /var/www/rainloop /var/www/zpush
when i click on this link for example: http://debian.local/cgi-bin/hobbitcolumn.sh?bbgen it download the .sh file instead of show it.
i tried to put fastcgi_ params in location ^~ /hobbit but still not working.
could you help me please
thanks
here is my sites-available/debian.local.conf:
# /etc/nginx/sites-available/debian.local.conf
# HTTP server
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
# Make site accessible from http://localhost/
server_name debian.local localhost ;
# On redirige toutes les requĂȘtes vers HTTPS
#rewrite ^ https://$server_name$request_uri? permanent;
location ^~ /glpi {
root /home/cedric/web;
index index.php;
location ~ /glpi(/.*\.php) {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
}
}
location ^~ /hobbit {
alias /usr/lib/hobbit/server/www/ ;
index index.html ;
}
location /cgi-bin/ {
alias /usr/lib/hobbit/cgi-bin/;
}
location /cgi-secure/ {
alias /usr/lib/hobbit/cgi-secure/ ;
}
}
server {
listen 443 ssl;
server_name debian.local localhost ;
root html;
index index.html index.htm;
# Use a self-signed certificate to ensure
# secure connexion to phpmyadmin
ssl_certificate debian.local.crt;
ssl_certificate_key debian.local.key;
ssl_session_timeout 5m;
# Access only latest browsers
ssl_protocols TLSv1.2;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
ssl_prefer_server_ciphers on;
location / {
try_files $uri $uri/ =404;
}
location /zabbix {
if ($scheme ~ ^http:){
rewrite ^(.*)$ https://$host$1 permanent;
}
alias /usr/share/zabbix;
index index.php;
error_page 403 404 502 503 504 /zabbix/index.php;
location ~ \.php$ {
if (!-f $request_filename) { return 404; }
expires epoch;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~ \.(jpg|jpeg|gif|png|ico)$ {
access_log off;
expires 33d;
}
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
## Xcache admin pages
location /xcache {
alias /usr/share/xcache/;
try_files $uri $uri/ /index.php;
location ~ ^/xcache/(.+\.php)$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
}
this is what appear instead of the web page:
#!/bin/sh QS="${QUERY_STRING}" QUERY_STRING="db=columndoc.csv&key=${QS}" export QUERY_STRING . /usr/lib/hobbit/server/etc/hobbitcgi.cfg exec /usr/lib/hobbit/server/bin/bb-csvinfo.cgi $CGI_HOBBITCOLUMN_OPTS
You should use the default_type directive in the interested location, for example:
location /cgi-bin/ {
alias /usr/lib/hobbit/cgi-bin/;
default_type text/plain;
}
I made it work.
This helped me: https://www.howtoforge.com/serving-cgi-scripts-with-nginx-on-debian-squeeze-ubuntu-11.04-p3
i intalled Fcgiwrap and edited my sites-available/debian.local.conf like this:
location /cgi-bin/ {
# Disable gzip (it makes scripts feel slower since they have to complete
# before getting gzipped)
gzip off;
# Set the root to /usr/lib (inside this location this means that we are
# giving access to the files under /usr/lib/cgi-bin)
alias /usr/lib/hobbit/cgi-bin/;
# Fastcgi socket
fastcgi_pass unix:/var/run/fcgiwrap.socket;
# Fastcgi parameters, include the standard ones
include /etc/nginx/fastcgi_params;
# Adjust non standard parameters (SCRIPT_FILENAME)
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Thanks.
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; }
}
I have to configure multi https website with a dedicated certificate for each website. It works fine like that.
server {
listen 443;
server_name client1.localhost.eu;
ssl on;
ssl_certificate ...;
ssl_certificate_key ...;
root /var/www/client1;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm-client1.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
server {
listen 443;
server_name client2.localhost.eu;
ssl on;
ssl_certificate ...;
ssl_certificate_key ...;
root /var/www/client2;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm-client2.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Now, I would like to factorize the "location" block, because it is always the same. Is it possible ?
(I have also tried to have only on server block, but it's not possible to put a variable in the ssl attribute)
Thanks a lot for your help.
Eric
Use include directive for such factorization:
include
Create file in the nginx config folder like
/etc/nginx/conf.d/location_php.cnf (not .conf to avoid auto-loading by nginx)
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm-client2.sock;
fastcgi_index index.php;
include fastcgi_params;
}
and then include it into server blocks:
server {
listen 443;
server_name client1.localhost.eu;
ssl on;
ssl_certificate ...;
ssl_certificate_key ...;
root /var/www/client1;
include /etc/nginx/conf.d/location_php.cnf;
# OR use relative path to nginx config root:
# include conf.d/location_php.cnf;
}