nginx subfolder setup, reach from another server.

Technical Support
  • I think i found a bug.

    Two servers, lets call them client and forum.
    Client server is hosting simple site, but it also have link to forum.
    Forum server is hosting nodebb.

    client nginx.conf

    server {                                                                                                                                                                
        listen 443 ssl http2;                                                                                                                                                                                                                                                                   
        server_name site.client.com;                                                                                                                                   
        include /usr/local/nginx/conf/ssl_auto.conf;                                                                                                              
        location /forum { try_files $uri @nodebb; }                                                                                                                         
        location @nodebb {                                                                                                                                                  
            proxy_set_header X-Forwarded-Proto $scheme; 
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #proxy_set_header Host $http_host;                                                   
            proxy_set_header X-NginX-Proxy true;                                                 
            proxy_pass_request_headers on;                                 
            proxy_redirect off;                                                                                   
            # Socket.IO Support                                                                  
            proxy_http_version 1.1;                                                              
            proxy_set_header Upgrade $http_upgrade;                                              
            proxy_set_header Connection "Upgrade";   
            proxy_pass https://site.forum.com;
    }
    

    forum nginx.conf

    upstream site_forum    {                                                                                                                                                                                                                                                                                               
        server unix:/tmp/nodebb.sock fail_timeout=0;                                                                                                                                                                                                          
    } 
    server {                                                                                                                                                                
        listen 443 ssl http2;                                                                                                                                               
        root /forum/nodebb/;                              
        server_name site.forum.com;                                   
        include /usr/local/nginx/conf/ssl.conf;
        location /forum { try_files $uri @nodebb; }                                    
        location @nodebb {                                                                            
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Real-IP $remote_addr;                                             
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                         
            #proxy_set_header Host $http_host;                                                   
            proxy_set_header X-NginX-Proxy true;                                                 
            proxy_pass_request_headers on;                           
            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://site_forum;                                                                                                                    
        }
    

    }

    Right now when user will go to site.client.com/forum, he will see nodebb, and everything would be alright, but ...

    when i log in to forum, some weird url redirect happens and path not follow forum config. Let me explain with examples:

    When i log in i get redirected to:

    1. https://site.client.com/?loggedin=true and it should be https://site.client.com/forum/?loggedin=true
    2. https://site.client.com/categories?loggedin=true and it should be https://site.client.com/forum/categories?loggedin=true
    3. https://site.client.com/topic/1/welcome-to-your-nodebb?loggedin=true and it should be https://site.client.com/forum/topic/1/welcome-to-your-nodebb?loggedin=true

    ... so it just cuts out forum part. If i type forum to web browser like it should be, everything is fine, but not when logging in.

    I think nodebb is responsible for this rewrite 🙂 or i miss something in config?

    Heres the browser console error when logging in:
    The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.

    Hm i found stack trace JS in browser problem could be here but i could also be wrong 🙂

    assets/src/client/login.js

    success:function(e){ var n=utils.urlToLocation(e.next).pathname;
    var r=utils.params({url:e.next});
    r.loggedin=true;
    var o=decodeURIComponent($.param(r));
    window.location.href=n+"?"+o}
    
  • Reinstalled nodebb and still the same problem.

  • What is your url value configured in config.json? It should match exactly the url at which you access the forum, including the correct protocol and subfolder.

  • Its "url": "https://site.client.com/forum/"

    Checked again and now this nginx config is not working 😞 it must be something with nginx im testing it again.

  • After fighting with nginx i just removed parts from nginx that are not needed to just reproduce this weird login redirect behavior.

    NodeBB nginx subfolder setup.

    upstream site_forum    {                                                                                                                                                                                                                                                                                               
        server unix:/tmp/nodebb.sock fail_timeout=0;                                                                                                                                                                                                          
    } 
    server {                                                                                                                                                                
        listen 443 ssl http2;                                                                                                                                               
        root /forum/nodebb/;                              
        server_name site.com;                                   
        include /usr/local/nginx/conf/ssl.conf;
        location /forum { try_files $uri @nodebb; }                                    
        location @nodebb {                                                                            
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Real-IP $remote_addr;                                             
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                         
            proxy_set_header Host $http_host;                                                   
            proxy_set_header X-NginX-Proxy true;                                                                                                                                     
            # Socket.IO Support                                                                  
            proxy_http_version 1.1;                                                              
            proxy_set_header Upgrade $http_upgrade;                                              
            proxy_set_header Connection "Upgrade";
            proxy_pass http://site_forum;                                                                                                                    
        }
    

    }

    config.json url : https://site.com/forum

  • If i change /public/src/client/login.js to ...

    success: function (data) {                                                   
        var pathname = utils.urlToLocation(data.next).pathname;                  
        var params = utils.params({ url: data.next });                           
        params.loggedin = true;                                                  
        var qs = decodeURIComponent($.param(params));                            
        window.location.href = pathname + 'forum/?' + qs;                        
    },
    

    nodebb build, nodebb upgrade, ... everything works as expected.

  • @MoJo Ah yeah it looks like you've run into this bug: https://github.com/NodeBB/NodeBB/issues/8515

    You'll need to cherry-pick the referenced commit to fix it in your install.


Suggested Topics


  • 0 Votes
    2 Posts
    359 Views

  • 0 Votes
    3 Posts
    2351 Views

  • 0 Votes
    1 Posts
    2169 Views

  • 0 Votes
    4 Posts
    2420 Views

  • 0 Votes
    8 Posts
    8657 Views

| | | |