1

I am trying to deploy a phpBB forum behind a load balancer that will distribute the traffic:

  • If https://example.com/forum/*, redirect to instance A (phpbb + nginx)
  • Any other path on https://example.com/, redirect to instance B (other stuff)

Therefore, I want to have phpBB installed on instance A and available under https://example.com/forum/.

On instance A, I am running nginx. Here's my nginx.config (with the important stuff only):

http {
    server {
        listen [::]:443 http2 ssl default_server;
        listen      443 http2 ssl default_server;
        server_name example.com;

        # PHP BB
        root /var/www/mysite/forum/src;

        # fastcgi
        include /etc/nginx/conf.d/fastcgi-php.conf;

        location /forum {
            index index.php index.html index.htm;
            rewrite ^/forum/(.*) /$1 break;
            try_files $uri $uri/ @rewrite_app;
        }

        location ~ \.php(/|$) {
            try_files $uri $uri/ /app.php$is_args$args;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        }

        location @rewrite_app {
            rewrite ^(.*)$ /app.php/$1 last;
        }
    }
}

Here are my problems:

  • When I visit https://example.com/forum/ the forum loads but all internal links are written without the /forum/ path, making the load balancer redirect to instance B.
  • When I visit https://example.com/forum/index.php, internal links are written correctly with the /forum/ path, but I get a phpBB application 404 The page is not found.

What am I doing wrong ?

Starscream
  • 111
  • 3
  • I think that you "location /forum" is relative to a root like /var/www/mysite/forum/src/forum and i don't think that is this what you want. – Federico Galli Apr 12 '18 at 10:37
  • Indeed it's not what I want. I'd like to serve `/forum` out of `/var/www/mysite/forum/src` without having to change my folder architecture. – Starscream Apr 12 '18 at 12:21
  • take a look at the alias and root directive in nginx https://stackoverflow.com/questions/10631933/nginx-static-file-serving-confusion-with-root-alias – Federico Galli Apr 12 '18 at 12:32

0 Answers0