Nginx configuration for WordPress websites

If you are using the WP Super Cache plugin by Automattic, this configuration can help you settings up your Nginx caching proxy:

[code]proxy_cache_path /data/nginx/cache keys_zone=one:10m inactive=24h max_size=1G;
proxy_cache_key “$host$request_uri$cookie_user”;
proxy_cache one;

server {
server_name ~^(static\.)?(?.+)$;
access_log /var/log/nginx/domains/static.$domain.log;

location ~ ^/(wp-content|wp-includes)/ {
expires 30d;
add_header Pragma public;
add_header Cache-Control “public”;
proxy_cache_valid 200 10m;
proxy_pass http://www.$domain;
add_header X-Cache-Status $upstream_cache_status;

Change the to the hostname the nginx server is listening to. Change (twice!) to the main domain where the content is pulled from.

Make a DNS record (either cname or a) pointing to the IP the nginx server is running at.

Be sure to chmod the /data/nginx/cache folder to 700 and change the ownership to the same user as nginx is running (default nginx).

Check if the cache is working by using this command:

[code]du -h –max-depth=1 /data/nginx/cache[/code]

Easy as that!