Serving up static content with nginx with nodebb running from subfolder.



  • I have nginx proxying to nodebb, from a /forum/ location.

    I wanted to serve up static contents with nginx - the example here - https://docs.nodebb.org/en/latest/scaling/#use-a-proxy-server-to-serve-static-assets assumes you have the forum running off the root. If running from a subfolder, it can be simplified to this (the public folder is tried first, followed by the proxy if no file exists).

    Here's my config using nginx to serve up the static content (just the locations/configs for nodebb included, I have a wordpress site running of the htdocs root)

    upstream io_nodes {
        ip_hash;
    
        server 127.0.0.1:4567; # upstream nodebb servers here
    }
    
    server {
        listen 443 default_server ssl;
        listen [::]:443 default_server ssl;
        server_name your.site;
    
        root /webroot/of/site;
        index index.html index.php;
    
        location /forum {
            alias /path/to/nodebb/public;
            try_files $uri @nodebb;
        }
    
        location @nodebb {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
    
            proxy_redirect off;
    
            # Socket.IO Support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
    
            proxy_pass http://io_nodes;
        }
    
    }
    

Log in to reply
 


Star

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.