WordPress nginx preview post is 404 not found, but old posts are working

I recently moved my wordpress site from one host to another. Previously i used Apache to run wordpress, but later on configured with nginx by following this tutorial How to Install WordPress with nginx on Ubuntu 12.04.

Everything works fine, but when i try to preview a new post from the admin panel it is showing not found error. But all already published posts are working fine.

Read More

When i click on preview post it is showing me url like
http://mydomain.com/?p=2671&preview=true but the page is 404.

The page title has Nothing found for ?p=2671&preview=true

My nginx configuration is:

server {
    listen    127.0.0.1:8080;
    #listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/www/mysite/public;
    index index.php index.html index.htm;

    server_name mydomain.com;   

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

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }       

    location ~ .php$ {
                #fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;

    }   
}

I also have installed All In One SEO Pack plugin and from my admin i enabled permalinks to this format /%year%/%monthnum%/%postname%/

I searched lot of forums but still couldn’t find the exact solution. Kindly help me on this.

Thank You

Related posts

Leave a Reply

4 comments

  1. Finally found the answer. It is the problem with Varnish configuration, it is not allowing to create a cookie.

    Open the varnish configuration. In my case the file is at /etc/varnish/default.vcl and add the following line

    # Drop any cookies sent to WordPress.
    sub vcl_recv {
            # Allow posts preview 
            if (req.url ~ "preview=true") { 
                    return(pass); 
            }
            if (!(req.url ~ "wp-(login|admin)")) {
                    unset req.http.cookie;
            }
    }
    

    and restart the nginx and varnish

    sudo service nginx restart
    
    sudo service varnish restart
    
  2. All i needed in my wordpress server is only 2 blocks

    location / {
        try_files $uri /index.php$request_uri;
    }
    location ~ .php {
        include fastcgi_params;
        fastcgi_pass   unix:/var/run/php5-fpm.sock; # replaced this with ur sock location
    }
    

    I don’t know about the SEO plugin, i use a different one.