Nginx, WordPress 3.9.2 and rewrites result in 404

I have never used Nginx before but I wanted to try it as an experiment and I am lost trying to setup pretty URLs up in WordPress.

However if I setup up Permalinks up to be anything other than query stings, it results in 404’s being thrown when try to go to a rewrote URL.

Read More

This is my Nginx conf could someone please let me know what I am doing wrong? I’ve tried multiple answers on similar questions without any luck.

Ngix Conf

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

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

    # Make site accessible from http://localhost/
    server_name site.co.uk;

    client_max_body_size 200M;

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

    # Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;

    location ~*  .(jpg|jpeg|png|gif|css|js|ico)$ {
            expires max;
            log_not_found off;
    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
          root /usr/share/nginx/html;
    }

    # 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;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;

    }
}

server {
        listen 80;
        server_name www.site.co.uk;
        return 301 $scheme://site.co.uk$request_uri;
}

So for example if I try to go to site.co.uk/my-account this is where the error happens.

Thanks in advance.
Matt

Related posts

Leave a Reply

1 comment