danaa
By:
danaa

WordPress post name permalink on LEMP (nginx) returns 404

January 8, 2015 3.3k views

Hi,

I tried everything I could and will document it, so posting here is my last resort.

I'm a designer/front-end developer and I tend to have a lot of different sites for different clients on a single droplet, organized in sub directories.

I have one WordPress install at domain.org/dev/wordpress/ and when I try to use post name permalink, all pages except homepage in WordPress spits out 404. This line in /etc/nginx/sites-available/default:

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

Solves the 404 issue on the WordPress site, however the problem is that it applies to every other pages. Every time when you enter the invalid url on my domain, it will redirect to that WordPress 404 page and this is something we don't want.

As a non-programmer, I attempted this, in hope that this line will only apply to THAT WordPress site:

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

Unfortunately, this line doesn't work - every time I try to load a .php page in WordPress site, instead of loading the page, the browser requests me to download the php file.

Is there anybody who can help me out with this? I also plan to create other WordPress site for other client project, do I still need to reconfigure nginx to support the permalink? Perhaps apache2 would work better for my kind of situation?

All helps would be appreciated. Thanks!

1 comment
  • Just curious, but what does this do:

    location /dev/wordpress/ {
          try_files $uri $uri/ /dev/wordpress/index.php?q=$uri&$args;
    }
    
Be the first one to answer this question.