Running in a sub folder with nginx


#1

Hello everyone,

I am trying to run rocket.chat behind a nginx reverse proxy but in a subfolder… the configuration that is shown in the documentation works but only on “location /” and we would like to use “location /chat”.

My nginx configuration is as follow:

Upstreams

upstream backend {
server 127.0.0.1:3000;
}

Default server configuration

server {
listen 80 default_server;
listen 443 ssl default_server;
include snippets/self-signed-cert.conf;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name xxxxxxxx;
location /chat {
proxy_pass http://backend/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
proxy_set_header Host $http_host;

            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forward-Proto http;
            proxy_set_header X-Nginx-Proxy true;

            proxy_redirect off;
    }

I get a bunch of lines like the following:

[error] 26822#26822: *5 open() “/var/www/html/sounds/highbell.mp3” failed (2: No such file or directory), client: yyy.yyy.yyy.yyy, server: xxx.xxx.xxx.xxx, request: “GET /sounds/highbell.mp3 HTTP/1.1”, host: “xxx.xxx.xxx.xxx”, referrer: “http://xxx.xxx.xxx.xxx/chat/

Anybody has any idea?

Thanks in advance for any help on this matter.

Regards.


#2

Sounds like inside Rocket.Chat you need to make sure you set your site URL to yourdomain.com/chat

Its attempting to access assets at yourdomain.com/


#3

Thanks for your reply aaron.ogle,

I’ve tried doing the change you suggest but still I get the same result…

Any other ideas?


#4

You restarted right after as well?


#5

Yes of course aaron.ogle! :slight_smile: , both nginx and rocket.chat… but still the same result. I am losing my head here… I really don’t get it. If I use “location /” on my nginx configuration and “https://IP_ADDRESS” on site URL on my rocket.chat installation it works perfectly!, the only thing I would have to change is “location /chat” on nginx configuration and “https://IP_ADDRESS/chat” on rocket.chat URL configuration! (right???)

Thanks for the help on this!


#6

Does anybody know how to change the following apache configuration to nginx:

<Location /chat>
Order allow,deny
Allow from all

RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /var/www/(.*)           ws://localhost:3000/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /var/www/(.*)           http://localhost:3000/$1 [P,L]

ProxyPassReverse http://localhost:3000

#7

Take a look here: https://rocket.chat/docs/installation/manual-installation/configuring-ssl-reverse-proxy/#running-behind-a-nginx-ssl-reverse-proxy

Basically something like this I think should do the trick:

location ~/chat(.*)$ {
        proxy_pass http://backend/$1;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forward-Proto http;
        proxy_set_header X-Nginx-Proxy true;

        proxy_redirect off;
    }

I haven’t tried. Not a big fan of subfolder :slight_smile: