Rewrites to get PHP and Statics Working in Virtual Sub Folders

HonDev Developer developerhondev at gmail.com
Wed Jan 2 03:23:21 MSK 2008


Using MU Wordpress with the folder install as opposed to the subdomain
install I initially couldn't get the admin section php files or the statics
working.

MU Wordpress folder install creates blogs like so:

domain.com/blog/
domain.com/secondblog/
domain.com/thirdblog/

The admin section is handled by the folders in the root physical location:

/home/site/public_html/wp-admin

The admin sections on the blogs are mapped to:

domain.com/wp-admin/ (this is for the main blog which worked with no
changes)
domain.com/secondblog/wp-admin/
domain.com/thirdblog/wp-admin/

The admin sections on the blogs also has virtual static files like this:

domain.com/secondblog/wp-admin/wp-admin.css

I got all this working with the adding the following to the conf.  I'm just
wondering, is there a better way to do it?

...

location ~*
^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
{
root /home/THEBLOG/public_html;
rewrite
^/.*(/wp-.*/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$
$1;
expires 10d;
break;
}

...

location ~ \.php$ {
rewrite ^/.*(/wp-admin/.*.php)$ $1;
fastcgi_pass   127.0.0.1:xxxx;

....

So the entire conf file is this on Nginx 0.6.4 :

server {
listen       80;
server_name  THEBLOG.com;

access_log  logs/THEBLOG.access.log;

location ~*
^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
{
root /home/THEBLOG/public_html;
rewrite
^/.*(/wp-.*/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$
$1;
expires 10d;
break;
}

location / {
root   /home/THEBLOG/public_html;
index  index.php;

rewrite ^.*/files/(.*) /wp-content/blogs.php?file=$1;

if (!-e $request_filename) {
rewrite ^.+/?(/wp-.*) $1 last;
rewrite ^.+/?(/.*\.php)$ $1 last;
rewrite ^(.+)$ /index.php?q=$1 last;
}

}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /var/www/nginx-default;
}

location ~ \.php$ {
rewrite ^/.*(/wp-admin/.*.php)$ $1;
fastcgi_pass   127.0.0.1:xxxx;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME
/home/THEBLOG/public_html$fastcgi_script_name;
include        /usr/local/nginx/conf/fastcgi_params;
}
}

server {
server_name www.THEBLOG.com;
rewrite ^/(.*) http://THEBLOG.com/$1 permanent;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20080102/538e140f/attachment.html>


More information about the nginx mailing list