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:
1. 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.
2. 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.