NGINX Error


  • GNU/Linux

    Hi,

    I dont want to setup my forum over a subdomain. Instead I would like to use a "folder" (https://domain.tld/forum/). I changed the NGINX configuration this way:

    server {
        listen 80;
    
        server_name domain.tld
    
        location /forum/ {
            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 http://127.0.0.1:4567/;
            proxy_redirect off;
    
            # Socket.IO Support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
    }
    

    This does actually work, but it doesn't load the stylesheets, javascripts etc. over /forum/, instead it tries to get the files over the root domain (domain.tld/). What do I have to change to make NodeBB get the files over the "folder"?

    Silas


  • Global Moderator

    What's in your config.json under base_url? (Nodebb folder)


  • GNU/Linux

    @a_5mith

    {
    "base_url": "https://domain.tld/forum/",
    "port": "4392",
    "secret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "bind_address": "0.0.0.0",
    "database": "redis",
    "redis": {
        "host": "127.0.0.1",
        "port": "6379",
        "password": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
        "database": "x"
    },
    "bcrypt_rounds": 12,
    "upload_path": "/public/uploads",
    "use_port": false,
    "relative_path": ""
    }


  • Grabbed and slighty modified form the doc, i think you want to serve statics things with nginx ?

    server {
    listen 80;
    
    server_name YOURSUBDOMAIN.domain.tld;
    
    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_redirect off;
    
    # Socket.io Support
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    
    gzip            on;
    gzip_min_length 1000;
    gzip_proxied    off;
    gzip_types      text/plain application/xml application/x-javascript text/css application/json;
    
    location @nodebb {
        proxy_pass http://127.0.0.1:4567;
    }
    
    location ~ ^/(images|language|sounds|templates|uploads|vendor|src\/modules|nodebb\.min\.js(\.map)?|stylesheet\.css|admin\.css) {
        root /path/to/nodebb/public/;
        try_files $uri $uri/ @nodebb;
    }
    
    location / {
        proxy_pass http://127.0.0.1:4567/;
    }
    

    }


  • GNU/Linux

    @Technowix

    Well, I saw that too. But the problem with this is that I have my Domain (domain.tld) where some static html files are located, what I want is that the forum runs over /forum/. If I rewrite the static files now, the static files on / get also rewritten which will cause some errors on /.



  • If i heard right, you want to run your forum on a http://mywebsite.com/forum right ?


  • GNU/Linux

    @Technowix

    Sorry for my late answer, and yeah thats right. But some other stuff ist located on http://mywebsite.com/, and I dont want to rewrite that. But the code:

    location ~ ^/(images|language|sounds|templates|uploads|vendor|src\/modules|nodebb\.min\.js(\.map)?|stylesheet\.css|admin\.css) {
       root /path/to/nodebb/public/;
       try_files $uri $uri/ @nodebb;
     }
    

    looks like it does also rewrite the files for http://mydomain.com



  • Did you change

    root /path/to/nodebb/public/;
    

    ?


  • GNU/Linux

    @Technowix

    I think you dont understand me. I havent tried your solution yet, because I think

     location ~ ^/(images|language|sounds|templates|uploads|vendor|src\/modules|nodebb\.min\.js(\.map)?|stylesheet\.css|admin\.css) {
        root /path/to/nodebb/public/;
        try_files $uri $uri/ @nodebb;
     }
    

    is going to rewrite the files for mydomain.com/forum/ AND mydomain.com/ - I dont want that.



  • Sorry, my english isn't pretty good x'D, i can't ashwer that.
    Also, why you don't make the use of a simple subdomain ? ^^' With a redirect mapping for your old forum ?


  • GNU/Linux

    @Technowix

    Well, I simply dont want to use subdomains. Maybe

    location ~ ^/forum/(images|language|sounds|templates|uploads|vendor|src\/modules|nodebb\.min\.js(\.map)?|stylesheet\.css|admin\.css) {
    root /path/to/nodebb/public/;
    try_files $uri $uri/ @nodebb;
    }
    

    would work?



  • Yeah, with that, i think (i'm not a nginx expert) nginx will simply try to search all statics things in /forum/ ! Also don't forget to change

    root /path/to/nodebb/public/;

    !


  • GNU/Linux

    Well, that doesnt work. Could somebody official (@psychobunny, @a_5mith, @julian) give me NGINX and NodeBB config files which allow the use of NodeBB over https://domain.tld/forum/? Help would be much appreciated.



  • The location for the files is prepended by a /.
    For your aim it has to be removed. source

    <link rel="stylesheet" type="text/css" href="/stylesheet.css?xxxxx">
    

    to

    <link rel="stylesheet" type="text/css" href="stylesheet.css?xxxxx">
    

    For this to work code would have to be rewritten. Good luck with this.

    Why do you want to make your live harder with constantly avoiding subdomains.
    They are much cleaner. And I think "the officials" will not come to "rescue" you.


  • Global Moderator

    @silasrech To add to what @termnml has said, My default instinct was to recommend you use a subdomain, as I'm not 100% that subfolders are really "supported". But I'm sure someone will give you a definitive answer. Unfortunately I'm also not really official. :p Have a read through this topic it contains some config settings etc to get it working as a subfolder.



  • Any correctly matched, arbitrary , location block should work.

    If I was better at them, I'd provide an example. :) Sorry.

    Fortunately, there are much smarter people than I out there who have done this - with Ghost. You should be able to use this while only changing the target port.

    An alternate hack would be to put a redirect on a subdirectory location block sending it to the subdomain config. Kinda fugly, but. :)


  • GNU/Linux

    After one year and diving deep into NGINX configuration and Node development I've finally found a solution for using subfolders with NGINX and NodeBB:

    NGINX configuration:

    server {
        listen 443 ssl;
        listen 80;
        listen [::]:443 ssl;
        listen [::]:80;
        server_name domain.tld;
        index index.html;
        location ^~ /community {
            proxy_set_header X-Real-IP         $remote_addr;
            proxy_set_header Referer           $http_referer;
            proxy_set_header Host              $host;
            proxy_set_header Cookie            $http_cookie;
            proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Host  $host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Port  $server_port;
            proxy_set_header X-NginX-Proxy     true;
            proxy_redirect                     off;
            proxy_http_version                 1.1;
            proxy_pass                         http://localhost:<port>;
        }
        location / {
             // stuff for your main app
        }
    }
    

    NodeBB configuration part:

    {
        "url": "https://domain.tld/community"
    }
    


  • @lenovouser it is already mentioned in the documentation, if I am not mistaken.


  • Global Moderator

    @lenovouser Yeah, I got that working pretty easily based on the docs. I did change from that to using a subdomain, though, because it just makes relative urls much easier.


  • GNU/Linux

    I can't find it in the documentation. You also find a lot of people asking for it, like me, if you search for it:

    search:subfolder


Log in to reply
 


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