Tricky Rewrite rules.

Hone developerhondev at gmail.com
Thu Nov 22 05:02:07 MSK 2007


Maybe another way to do it would be to set up a second backend instance
of nginx on another port which serves all the php dynamic.

1. http client makes request
2. if static is required and available the front nginx serves it
3. if no static is found the request gets proxied to the second nginx
server with php fastcgi

Your 2nd Nginx would have your normal rewrites and the fastcgi php set
up and your first file could look like this.  I haven't had time to test
this.

upstream 2ndNginx {
server 127.0.0.1:82;
}

server {
listen 80;
server_name supercachestatic.com;
location / {

root   /var/www/mydomain.com/htdocs;
index  index.html;


if ($query_string !~ ".*s=.*") {
 rewrite ^(.*) /wp-content/cache/supercache/$http_host/$1index.html;
}

if ($http_cookie !~ "^.*comment_author_.*$" ) {
 rewrite ^(.*) /wp-content/cache/supercache/$http_host/$1index.html;
}

if ($http_cookie !~ "^.*wordpressuser.*$" ) {
 rewrite ^(.*) /wp-content/cache/supercache/$http_host/$1index.html;
}

if ($http_cookie !~ "^.*wp-postpass_.*$" ) {
 rewrite ^(.*) /wp-content/cache/supercache/$http_host/$1index.html
break;
}

error_page    404  =  @2ndNginx;

}

location @2ndNginx {
proxy_pass http://2ndNginx;

}






More information about the nginx mailing list