MyBB Community Forums

Full Version: Put MyBB in nginx /forum location config
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I have a VPS that I have Wordpress running on that I want to remain using htpcguides.com. I am trying to make mybb be in htpcguides.com/forum but for the life of me I cannot get it to work. If anybody has this working can you please share your vhost configuration?

Without trying to use /forum as the custom location this configuration works beautifully, when I try to make the adjustments as shown below, I can point to htpcguides.com/forum/install and it downloads the php file instead of executing it, if I remove the /forum bits it works just fine.

server {
    listen       80;
    server_name default_server;
    root /var/www/mybb;

    access_log   /var/log/nginx/forum.htpcguides.com.access.log;
    error_log    /var/log/nginx/forum.htpcguides.com.error.log;

    location /forum {
    server_tokens off;
    index index.html index.htm index.php;
   rewrite ^/forum/forum-([0-9]+)\.html$ /forumdisplay.php?fid=$1;
    rewrite ^/forum/forum-([0-9]+)-page-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2;
    rewrite ^/forum/thread-([0-9]+)\.html$ /showthread.php?tid=$1;
    rewrite ^/forum/thread-([0-9]+)-page-([0-9]+)\.html$ /showthread.php?tid=$1&page=$2;
    rewrite ^/forum/thread-([0-9]+)-lastpost\.html$ /showthread.php?tid=$1&action=lastpost;
    rewrite ^/forum/thread-([0-9]+)-nextnewest\.html$ /showthread.php?tid=$1&action=nextnewest;
    rewrite ^/forum/thread-([0-9]+)-nextoldest\.html$ /showthread.php?tid=$1&action=nextoldest;
    rewrite ^/forum/thread-([0-9]+)-newpost\.html$ /showthread.php?tid=$1&action=newpost;
    rewrite ^/forum/thread-([0-9]+)-post-([0-9]+)\.html$ /showthread.php?tid=$1&pid=$2;
    rewrite ^/forum/post-([0-9]+)\.html$ /showthread.php?pid=$1;
    rewrite ^/forum/announcement-([0-9]+)\.html$ /announcements.php?aid=$1;
    rewrite ^/forum/user-([0-9]+)\.html$ /member.php?action=profile&uid=$1;
    rewrite ^/forum/calendar-([0-9]+)\.html$ /calendar.php?calendar=$1;
    rewrite ^/forum/calendar-([0-9]+)-year-([0-9]+)\.html$ /calendar.php?action=yearview&calendar=$1&year=$2;
    rewrite ^/forum/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html$ /calendar.php?calendar=$1&year=$2&month=$3;
    rewrite ^/forum/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html$ /calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4;
    rewrite ^/forum/calendar-([0-9]+)-week-(n?[0-9]+)\.html$ /calendar.php?action=weekview&calendar=$1&week=$2;
    rewrite ^/forum/event-([0-9]+)\.html$ /calendar.php?action=event&eid=$1;
    rewrite ^/forum/archive/index.php/forum-([0-9]+)\.html$ /forum/archive/index.php?forum-$1.html;
    rewrite ^/forum/archive/index.php/thread-([0-9]+)\.html$ /forum/archive/index.php?thread-$1.html;
        }
    location ~ /forum/(inc|uploads/avatars) {
        deny all;
        }
    location ~* \.(jpg|jpeg|gif|png|css|ico|xml)$ {
    access_log        off;
    log_not_found     off;
    expires           360d;
        }
    location ~ /forum/+.\.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/mybb/$fastcgi_script_name;
        }
    location ~ /\.ht {
        deny all;
        }
}
Hi, can you try replacing the PHP location block with the following?

location ~* \.php$ {
    try_files $uri =404;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

Really, you shouldn't need separate location blocks to handle PHP files for WordPress and MyBB (unless you're using separate FPM pools or something) as the $document_root variable should be used rather than the hardcoded document root you were using. If you use only the above, it should work Smile
Thanks for the reply Euan, it still doesn't work unfortunately. This works fine with your modification


server {

    listen       80;
    server_name default_server;
    root /var/www/mybb;

    access_log   /var/log/nginx/forum.htpcguides.com.access.log;
    error_log    /var/log/nginx/forum.htpcguides.com.error.log;

    location / {
    server_tokens off;
    index index.html index.htm index.php;
    rewrite ^/forum/forum-([0-9]+)\.html$ /forumdisplay.php?fid=$1;
    rewrite ^/forum/forum-([0-9]+)-page-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2;
    rewrite ^/forum/thread-([0-9]+)\.html$ /showthread.php?tid=$1;
    rewrite ^/forum/thread-([0-9]+)-page-([0-9]+)\.html$ /showthread.php?tid=$1&page=$2;
    rewrite ^/forum/thread-([0-9]+)-lastpost\.html$ /showthread.php?tid=$1&action=lastpost;
    rewrite ^/forum/thread-([0-9]+)-nextnewest\.html$ /showthread.php?tid=$1&action=nextnewest;
    rewrite ^/forum/thread-([0-9]+)-nextoldest\.html$ /showthread.php?tid=$1&action=nextoldest;
    rewrite ^/forum/thread-([0-9]+)-newpost\.html$ /showthread.php?tid=$1&action=newpost;
    rewrite ^/forum/thread-([0-9]+)-post-([0-9]+)\.html$ /showthread.php?tid=$1&pid=$2;
    rewrite ^/forum/post-([0-9]+)\.html$ /showthread.php?pid=$1;
    rewrite ^/forum/announcement-([0-9]+)\.html$ /announcements.php?aid=$1;
    rewrite ^/forum/user-([0-9]+)\.html$ /member.php?action=profile&uid=$1;
    rewrite ^/forum/calendar-([0-9]+)\.html$ /calendar.php?calendar=$1;
    rewrite ^/forum/calendar-([0-9]+)-year-([0-9]+)\.html$ /calendar.php?action=yearview&calendar=$1&$
    rewrite ^/forum/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html$ /calendar.php?calendar=$1&y$
    rewrite ^/forum/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html$ /calendar.php?$
    rewrite ^/forum/calendar-([0-9]+)-week-(n?[0-9]+)\.html$ /calendar.php?action=weekview&calendar=$$
    rewrite ^/forum/event-([0-9]+)\.html$ /calendar.php?action=event&eid=$1;
    rewrite ^/forum/archive/index.php/forum-([0-9]+)\.html$ /forum/archive/index.php?forum-$1.html;
    rewrite ^/forum/archive/index.php/thread-([0-9]+)\.html$ /forum/archive/index.php?thread-$1.html;
        }
    location ~ /forum/(inc|uploads/avatars) {
        deny all;
        }
    location ~* \.(jpg|jpeg|gif|png|css|ico|xml)$ {
    access_log        off;
    log_not_found     off;
    expires           360d;
        }
    location ~* \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

    location ~ /\.ht {
        deny all;
        }
}

As soon as I change location / to /forum
htpcguides.com/install returns forbidden
htpcguides.com/forum/install returns not found

Any other ideas?

When I try and use aliases I can't access anything but I figured I'll try and make the simple subdirectory work first before tackling that issue.
Suppress the '/forum' in your rewrite rules and locations.
Your board is on the domain root, not in a subdirectory.

If your forum is at http://www.htpcguides.com/forum/, modify the first location to add the /forum in it.
(2015-05-20, 12:21 PM)Crazycat Wrote: [ -> ]Suppress the '/forum' in your rewrite rules and locations.
Your board is on the domain root, not in a subdirectory.

If your forum is at http://www.htpcguides.com/forum/, modify the first location to add the /forum in it.

Thanks Crazycat, I have done what I think you meant and still not working, get a 404 error for http://www.htpcguides.com/forum/install in my test environment

I do want to use aliases when I'm all done because this config file needs to be merged with my wordpress configuration. It's driving me insane


server {

    listen       80;
    server_name default_server;
    root /var/www/mybb;
    access_log   /var/log/nginx/forum.htpcguides.com.access.log;
    error_log    /var/log/nginx/forum.htpcguides.com.error.log;

    location /forum {
    server_tokens off;
    index index.html index.htm index.php;
    rewrite ^/forum-([0-9]+)\.html$ /forumdisplay.php?fid=$1;
    rewrite ^/forum-([0-9]+)-page-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2;
    rewrite ^/thread-([0-9]+)\.html$ /showthread.php?tid=$1;
    rewrite ^/thread-([0-9]+)-page-([0-9]+)\.html$ /showthread.php?tid=$1&page=$2;
    rewrite ^/thread-([0-9]+)-lastpost\.html$ /showthread.php?tid=$1&action=lastpost;
    rewrite ^/thread-([0-9]+)-nextnewest\.html$ /showthread.php?tid=$1&action=nextnewest;
    rewrite ^/thread-([0-9]+)-nextoldest\.html$ /showthread.php?tid=$1&action=nextoldest;
    rewrite ^/thread-([0-9]+)-newpost\.html$ /showthread.php?tid=$1&action=newpost;
    rewrite ^/thread-([0-9]+)-post-([0-9]+)\.html$ /showthread.php?tid=$1&pid=$2;
    rewrite ^/post-([0-9]+)\.html$ /showthread.php?pid=$1;
    rewrite ^/announcement-([0-9]+)\.html$ /announcements.php?aid=$1;
    rewrite ^/user-([0-9]+)\.html$ /member.php?action=profile&uid=$1;
    rewrite ^/calendar-([0-9]+)\.html$ /calendar.php?calendar=$1;
    rewrite ^/calendar-([0-9]+)-year-([0-9]+)\.html$ /calendar.php?action=yearview&calendar=$1&year=$2;
    rewrite ^/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html$ /calendar.php?calendar=$1&year=$2&month=$3;
    rewrite ^/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html$ /calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4;
    rewrite ^/calendar-([0-9]+)-week-(n?[0-9]+)\.html$ /calendar.php?action=weekview&calendar=$1&week=$2;
    rewrite ^/event-([0-9]+)\.html$ /calendar.php?action=event&eid=$1;
    rewrite ^/archive/index.php/forum-([0-9]+)\.html$ /forum/archive/index.php?forum-$1.html;
    rewrite ^/archive/index.php/thread-([0-9]+)\.html$ /forum/archive/index.php?thread-$1.html;
        }
    location ~ /forum/(inc|uploads/avatars) {
        deny all;
        }
    location ~* \.(jpg|jpeg|gif|png|css|ico|xml)$ {
    access_log        off;
    log_not_found     off;
    expires           360d;
        }
    location ~* \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    location ~ /\.ht {
        deny all;
        }
}
I think your wordpress rewriting is overriding your mybb rewriting.
If you don't have the solution until tonight, I'll have a look on my configurations (can't access my servers yet) to do some tests.
why not use subdomain? like forum.htpcguides.com
more easy to configure...
I don't even have the two configurations combined at this point because mybb isn't working on its own (as its own singular vhost) in the /forum location yet so the Wordpress rewriting can't be happening (yet). I've been working on this yesterday and all day today so at this point I am hoping someone is running Wordpress and mybb on the same VPS using nginx like I want to and can share their config file. I would be very grateful if you can help me get this working. I was at the point where I started looking for a dev to hire which I usually avoid at all costs!

(2015-05-20, 01:32 PM)martec Wrote: [ -> ]why not use subdomain? like forum.htpcguides.com
more easy to configure...

I was thinking that but I am behind CloudFlare and only have a limited number of additional records (CNAME) I can add to it before I have to pay. It may also be an issue since I want to use https and the cheap certificates (I am told) don't support subdomains. As a last resort, I may do this but would prefer to avoid it, do you have a configuration working for the subdomain you can share?
(2015-05-20, 01:35 PM)blindpet Wrote: [ -> ]I was thinking that but I am behind CloudFlare and only have a limited number of additional records (CNAME) I can add to it before I have to pay. It may also be an issue since I want to use https and the cheap certificates (I am told) don't support subdomains. As a last resort, I may do this but would prefer to avoid it, do you have a configuration working for the subdomain you can share?

https://gist.githubusercontent.com/marte...tfile1.txt

i using this in my forum

Ps. Change listen 8080; to listen 80; i forgot to change this for you. I using 8080 because of varnish-cache.
Ps2. subdomain is A records and not Cnames records
(2015-05-20, 01:53 PM)martec Wrote: [ -> ]
(2015-05-20, 01:35 PM)blindpet Wrote: [ -> ]I was thinking that but I am behind CloudFlare and only have a limited number of additional records (CNAME) I can add to it before I have to pay. It may also be an issue since I want to use https and the cheap certificates (I am told) don't support subdomains. As a last resort, I may do this but would prefer to avoid it, do you have a configuration working for the subdomain you can share?

https://gist.githubusercontent.com/marte...tfile1.txt

i using this in my forum

Ps. Change listen 8080; to listen 80; i forgot to change this for you. I using 8080 because of varnish-cache.
Ps2. subdomain is A records and not Cnames records

Thank you very much! I actually use Varnish too so this is great, could you share your vcl rules for mybb too? Are you using Varnish 3 or 4?
Are you running Wordpress on the same server?

CloudFlare did seem to let me add another A record for forum so my next concern is SSL. The stubborn part of me really wants to make this /forum location work but I'm very happy the subdomain solution was proposed.
Pages: 1 2