Press "Enter" to skip to content

WordPress, nginx, and category links

I’m dabbling in gaining experience with web services in my spare time. I decided to bring my blog up under nginx rather than Apache. Everything seemed fine except that the category links oddly stopped working and led to a 404 result from nginx. Googling was strangely unproductive at first until I realized that the common guidance for fixing permalinks (which I did not see a problem with) also applied to category links.

The solution is to modify the location / directive in the server block to include a last-change rewrite to feed the URI back to WordPress’s index.php, and more importantly, to remove the =404 that causes nginx to fail when it can’t match the permalink to a file on disk. Specifically, my location originally read:

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

and needed to be changed to:

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

Now nginx will do the right thing. Yay.