How To Run phpBB on Nginx With Virtual Hosting
We now have our phpBB forum running on Nginx web server, a high quality and significantly better performing web server than Apache HTTPD. Soem of the challenges we faced were:
- We use nice permalinks in the forum so there are lots of apache httpd rewrite rules in .htaccess files which had to be converted to nginx format.
- Additionally we also had to configure it for a virtual hosting setup where the same IP address (server) is shared by multiple websites.
The key change we had to make was adding a / immediately after ^ in the rewrite condition expression. In Apache HTTPD the request URI doesn't contain an initial / while in nginx it does.As I mentioned before we use nice permalinks. The final rewrite rules for niginx for phpBB are:
rewrite ^/[a-z0-9_-]*-f([0-9]+)/?(p([0-9]+)\.html)?$ /viewforum.php?f=$1&start=$3 last;
# TOPIC WITH VIRTUAL FOLDER rewrite ^/[a-z0-9_-]*-f([0-9]+)/[a-z0-9_-]*-t([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?f=$1&t=$2&start=$4 last;
# GLOBAL ANNOUNCES WITH VIRTUAL FOLDER rewrite ^/announces/[a-z0-9_-]*-t([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?t=$1&start=$3 last;
# TOPIC WITHOUT FORUM ID & DELIM rewrite ^/[a-z0-9_-]*/?[a-z0-9_-]*-t([0-9]+)(-([0-9]+))?\.html$ /viewtopic.php?t=$1&start=$3 last;
# PROFILES SIMPLE rewrite ^/m([0-9]+)\.html$ /memberlist.php?mode=viewprofile&u=$1 last;
# USER MESSAGES SIMPLE rewrite ^/messages([0-9]+)(-([0-9]+))?\.html$ /search.php?author_id=$1&sr=posts&start=$3 last;
# GROUPS SIMPLE rewrite ^/g([0-9]+)(-([0-9]+))?\.html$ /memberlist.php?mode=group&g=$1&start=$3 last;
# POST rewrite ^/p([0-9]+)\.html$ /viewtopic.php?p=$1 last;
# THE TEAM rewrite ^/the-team\.html$ /memberlist.php?mode=leaders last; rewrite ^/[a-z0-9_-]+/?(p([0-9]+)\.html)?$ /viewforum.php?start=$2 last;
In Apache you can specify RewriteCond (rewrite conditions) that go with a rewrite rule. You cannot do the same in nginx. However what I did instead was:
if (-e $request_filename) {
break;
}
This ensures that existing files, directories or symbolic links are used instead of matching (and re-directing) them with rewrite rules.
We use the same IP to host several websites (virtual hosting) so we had to enclose the rewrite rules above within an if block where we apply it only when the host is forum.taragana.com. It looks like this:
if ($host ~* ^forum\.taragana\.com$) {
rewrite ^/[a-z0-9_-]*-f([0-9]+)/?(p([0-9]+)\.html)?$ /viewforum.php?f=$1&start=$3 last;
...
}
Hope that helps in setting up your nginx server for phpBB. If you have any questions on setting up phpBB on nginx please ask it in our forum.
Filed under Enterprise Software and Services, Headline News, How To, Linux, Open Source Software, Web, Web Hosting, Web Services, nginx | Tags: Apache HTTPD, nginx, phpBB, Rewrite Rules, Virtual Hosting, Web Server |
6 Comments |
Email this Article


















July 12th, 2008 at 8:16 am
[...] How to run phpBB on Nginx with / without Virtual Hosting [...]
November 13th, 2008 at 5:15 pm
I have a flash website
i’m looking for the script who of google ads on flash.
do you know this script?
January 12th, 2009 at 7:41 am
Hello People,
I Just joined up and am trying edit my profile but i can’t see the button!! probably staring me in the face lol
thanks guys
G
March 6th, 2009 at 5:58 pm
Great post dude,
Thanks alot……for sharing.
You are so helpful……
June 15th, 2009 at 5:29 pm
I heard from several sources that people didnt recieve the product they bought from amazon
is this true?
October 1st, 2009 at 11:06 am
please i want somebody to please mail me a web portal software so that i will download it