26 Oct
Nginx rewrites are simple but there’s not as much documentation as there is with Apache2. Here’s how I set up my rewrites on Nginx install of MU Wordpress and BBPress.
I’ll go through things bit by bit then give a complete server sample. (Not a complete conf file because other tutorials cover the rest of that better.)
In other words all this code will go in between:
server {......}
First of all you need to make sure you have static files set up so that the actual location is not over ridden with rewrites. Otherwise you’ll get a 404 error.
Here’s the code:
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/YOURDIRECTORY/public_html;
expires 30d;
break;
}
Note that here you need to change ‘yourdirectory’ to the directory which your public_html folder is.
If you don’t include the root of your folder and you have multiple sites in different home folders then Nginx will default to your first listed server root which is probably /usr/local/nginx/html. That will cause you 404’s.
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;
break;
}
location /forums/ {
root /home/YOURDIRECTORY/public_html/forums;
index index.php;if (!-e $request_filename) {
rewrite ^/forums/topic/(.*)$ /forums/topic.php?q=$1 last;
rewrite ^/forums/forum/(.*)$ /forums/forum.php?q=$1 last;
rewrite ^/forums/profile/(.*)$ /forums/profile.php?q=$1 last;
rewrite ^/forums/view/(.*)$ /forums/view.php?q=$1 last;
rewrite ^/forums/tags/(.*)$ /forums/tags.php?q=$1 last;
rewrite ^/forums/rss/(.*)$ /forums/rss.php?q=$1 last;
rewrite ^/forums/bb-admin/ /forums/bb-admin/index.php last;
rewrite ^/forums/ /forums/index.php last;break;
}
}
So that’s how you do the complete BBPress Wordpress MU Integration on Nginx with pretty URL rewrites. Click here for a nginx server conf file example. (Remember this is the server part of the entire nginx.conf file)
Leave a reply