Basic Example: WordPress Proxy Caching with FastCGI
miradev
nginx-forum at nginx.us
Fri Sep 3 21:55:44 MSD 2010
I would like to add caching to various wordpress installations (some
bloggy, some not). There are no caching plugins installed, as I'd like
nginx to handle the caching.
The current setup is fairly basic:
[code]
server {
listen 67.67.67.67:80;
server_name www.miradev.com miradev.com;
root /home/httpd/wordpress/www.miradev.com;
index index.php index.html index.htm;
access_log /var/log/nginx/wordpress/www.miradev.com-access.log;
error_log /var/log/nginx/wordpress/www.miradev.com-error.log;
if ($host != 'www.miradev.com') {
rewrite ^/(.*)$ http://www.miradev.com/$1 redirect;
}
location / {
try_files /system/maintenance.html $uri $uri/
/index.php?q=$uri&$args;
}
location ~ \.php($|/) {
set $script $uri;
set $path_info "";
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
set $path_info $2;
}
include wordpress/fcgi_generic_params.conf;
}
}
[/code]
And the fcgi config:
[code]
fastcgi_pass localhost:8887;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name; # same path as above
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REDIRECT_STATUS 200;
[/code]
My questions are:
1. How do I add caching to this?
2. How do I avoid caching admin pages?
3. What are the ways to expire generic caches as and when needed?
I have looked at various bits of documentation and blogs. They
predominantly focus on using Apache, which I am not using. I'm unclear
as to which blocks I should be putting the proxy* configurations.
There are multiple WP blogs (and PHP applications generally) served by
nginx, so the cache needs to be able to handle that (i.e. only cache
wordpress configs, not the other stuff).
(apologies for doubling posting, but 'how to' doesn't seem to get much
traffic)
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,126863,126863#msg-126863
More information about the nginx
mailing list