Wordpress permalink and cache help

jcaleb nginx-forum at nginx.us
Sat Nov 17 05:34:57 UTC 2012


Hello,  I have a wordpress website and want to enable caching.  My
configuration below is working if no pretty url  E.g.
http://domain.com/?page_id=2

But when I use pretty url, the cache doesnt work:  E.g.
http://domain.com/sample-page

But the pages displays correctly for both cases.

Thank you

<pre>
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:5m
max_size=1000m;

server {
    listen 80;
    server_name domain.com www.domain.com;

    access_log /var/log/nginx/website.access_log;
    error_log /var/log/nginx/website.error_log;

    root /home/jon/temp/php/domain.com;
    index index.php index.htm index.html;

    location ~ .php$ {
        set $no_cache "";
        if ($request_method !~ ^(GET|HEAD)$) {
            set $no_cache "1";
        }
        if ($no_cache = "1") {
            add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/";
            add_header X-Microcachable "0";
        }
        if ($http_cookie ~* "_mcnc") {
                    set $no_cache "1";
        }
        fastcgi_no_cache $no_cache;
        fastcgi_cache_bypass $no_cache;
        fastcgi_cache microcache;
        fastcgi_cache_key $server_name|$request_uri;
        fastcgi_cache_valid 404 30m;
        fastcgi_cache_valid 200 10s;
        fastcgi_max_temp_file_size 1M;
        fastcgi_cache_use_stale updating;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_pass_header Set-Cookie;
        fastcgi_pass_header Cookie;
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param  PATH_INFO          $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;
        include fastcgi_params;
    }

    location ~ \.(js|css|ico|png|jpg|jpeg|gif|swf|xml|txt)$ {
	access_log off;
        expires 30d;
    }

    location ~*
\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_
{
	return 444;
    }

    location ~ /\. {
	return 444;
	access_log off;
	log_not_found off;
    }

    location ~* \.(pl|cgi|py|sh|lua)\$ {
	return 444;
    }

    location ~* (roundcube|webdav|smtp|http\:|soap|w00tw00t) {
	return 444;
    }

    location / {
	try_files $uri $uri/ /index.php;
    }
}
</pre>

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,232940,232940#msg-232940



More information about the nginx mailing list