Home > Enterprise >  Wordpress error 404 in migration from Apache to Nginx
Wordpress error 404 in migration from Apache to Nginx

Time:05-10

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

CodePudding user response:

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