How to fix 404 not found nginx problem?

April 21, 2016 42.4k views
Nginx WordPress

I run Nginx on my wordpress site, but now all pages and categories, except homepage, suddenly appear "404 not found, Nginx", the permalinks are correct and i don't do anything before such problem occur. How can i troubleshoot and fix this problem?

Thank you!

1 comment
  • Hi!

    In order to be able to help you, please post your nginx server block config (usually /etc/nginx/sites-enabled/file.conf) and the last few lines of Nginx's error log:

    sudo tail -n 20 /var/log/nginx/error.log
    
6 Answers

Do you run a php-fpm interpreter or do you proxy-pass to a apache with php module running on your server? In first case please have all corresponding rewrite rules in your nginx config checked and static files locations to be set up to a right path. In the second case please check .htaccess file in your website root to be accessible by a webserver and to contain apropriate WP rewrite rules.

I did not understand what to do to solve.
Someone explain to me what is causing this problem?
Thank you!

I have exactly the same, everything worked well, and I don't know why, at one moment, all pages turned into 404 error. It works when I disabled permalinks, but I've tried everything..

Did you resolve your problem ? Thanks.

I still having this problem @kamaln7 help! my server block config etc/nginx/sites-enabled/kinbuweb is:

server {
    listen 80;
    listen [::]:80;

    root /var/www/kinbuweb/public;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name kinbu.localhost;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
    location ~ /\.ht {
        deny all;
    }
}

And my sudo tail -n 20 /var/log/nginx/error.log from when I started having the problem:

2017/01/30 16:42:58 [notice] 2385#2385: signal process started
2017/01/30 16:46:45 [notice] 2468#2468: signal process started

Change the line in the location block to:

try_files $uri $uri/ /index.php?q=$uri&$args;

and reload nginx

sudo systemctl reload nginx

All should be well :)

Have another answer? Share your knowledge.