Nginx – 404 error with nginx and wordpress

nginxWordpress

My wordpress site has been working fine for sometime with nginx and wordpress. But for some reason it is now giving me a 404 error. I think this may be related to the quick-cache plugin which I recently updated. Although I'm not 100% sure about this.

To setup wp-nginx I following these instructions. So far I've done the following

  • deleted my plugin directory
  • removed reference to quick-cache from wp-config.php /wp-content folder
  • checked my nginx config which is below

However after restarting I still get the same 404 error. Would anyone know what could be wrong..?

server {
    listen   80;


    root /var/www;
    index index.php index.html index.htm;

    server_name mysite.com;

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

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
          root /var/www;
    }

    # pass the PHP scripts to FastCGI server listening on the php-fpm socket
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }

}

Best Answer

Your config is not okay.

Here is working WordPress config file.

server {
                listen 80;
                server_name www.mysite.com mysite.com;
                access_log /var/log/nginx/mysite.access.log;
                error_log /var/log/nginx/mysite.error.log;
                root /var/www/html;
                index index.php index.htm index.html;

location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}

location ~ /\. {
    access_log off;
    log_not_found off; 
    deny all;
}
location /favicon.ico { access_log off; log_not_found off; }
location ~* \.(jpg|jpeg|gif|png|js|xml)$ {
    access_log        off;
    log_not_found     off;
    expires           360d;
}
                location ~ .php$ {
                  fastcgi_pass 127.0.0.1:9000;
                  fastcgi_index index.php;
                  fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
                  include fastcgi_params;
                }
       }