WordPress

Nginx works perfectly well with a wide variety of applications, and WordPress is certainly one of them. NginX's configuration language is very powerful and straightforward if one is familiar with it, but often people coming from other servers are not sure how things work in NginX and just copy and paste whatever they see from a blog that seems to fill their needs. Everyone, especially people new to NginX, should check out the nginx.org documentation for an overview of how things work and should be done in NginX.

Abridged basic setup

Hopefully you have read the documentation above and maybe worked on setting up a virtual server or two in Nginx already - if not there are a few notes below, but you should still read the documentation.

First we setup a named upstream for our php, which allows us to abstract the backend and easily change the port or add more backends. After that, we setup our virtual host configuration for domain.tld.

With this configuration we should be able to serve wordpress very easily. Once you setup your backend (php-cgi or php-fpm) should work perfectly.

Location Strategies

There are many ways to declare your locations in your configuration that allow you to do basically whatever you want with your URLs. Usually, people want to have "pretty" URLs that hide the query strings and script files. Here are a few different strategies based on different goals. Here we are defining locations that should be used to replace the basic locations above in order to achieve the desired results.

Non-root try_files to URL redirect

If you want to serve WordPress as a sub directory, you will want to make the following changes (relative to the above configuration).

Notes

map section can be completed manually for small sites. On large multisite network nginx-helper wordpress plugin can be used.

Further performance gain is possible by using Nginx's fastcgi_cache. When using fastcgi_cache, compile nginx with ngx_cache_purge module and add a wordpress-plugin which performs automatic cache purge on events e.g. a wordpress post/page is edited.