NGINX Error
-
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.
-
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.
-
@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.
-
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:
-
Edit: while that doesn't explain it entirely, you really only need to change the location in the Nginx and the URL in the config.
-
Hm.
Just changing
location /
to
location /community
will definitely not work. I've tried that. You need the
^~
to make it work. -
@lenovouser it worked for me first time. There must be something else going on with your configuration. Maybe it's the SSL or something, since my test server was just running on 80.
-
Might be, but I don't know how SSL should interfere with location blocks. Might spin a droplet up sometime later this day and test it.
-
Actually, you see what the error is if you look at my first 2 posts.
-
@lenovouser Your method works fine for me over https. Thanks for your persistence.
edit: I just had to add in these two lines for socket.io to work.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";