Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nginx + Docker subfolder configuration #11460

Closed
olegberman opened this issue Jul 13, 2018 · 8 comments
Closed

Nginx + Docker subfolder configuration #11460

olegberman opened this issue Jul 13, 2018 · 8 comments

Comments

@olegberman
Copy link

olegberman commented Jul 13, 2018

Description:

Not able to get Rocket.chat to work in a subfolder https://domain.com/chat with Docker + Nginx. Can anyone possibly share their working configuration?

Expected behavior:

Chat to load as usual.

Actual behavior:

These are errors that I'm getting (this is the closest I got to get it running):

issue 2

issue

Server Setup Information:

  • Using CentOS
  • Running recent Rocket.chat release in Docker (with docker-compose)

Configs

nginx.conf

  # the nginx server instance
  server {
      server_name domain.com;

      location / {
         # ... different app
      }

	location /chat/ {
            # ... some irrelevant stuff

           proxy_http_version 1.1;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection 'upgrade';
           proxy_set_header Host $host;
           proxy_cache_bypass $http_upgrade;
           proxy_pass http://0.0.0.0:3000/;
           proxy_redirect off;
	}

        # found this hack in one of the issues to make /sockjs endpoint work
        location /sockjs {
        	proxy_http_version 1.1;
        	proxy_set_header Upgrade $http_upgrade;
        	proxy_set_header Connection 'upgrade';
        	proxy_set_header Host $host;
        	proxy_cache_bypass $http_upgrade;
        	proxy_pass http://0.0.0.0:3000/sockjs;
        	proxy_redirect off;
        }

    listen 443 ssl; # managed by Certbot
    ... irrelevant certbot stuff
}

Additional context

Hosting on the subdomain working just fine!

Now it looks like Rocket.chat tries to call /api path, and I can't add the same hack as location /sockjs { as I have an API for a different app there. It should be calling /chat/api and /chat/sockjs ideally.

Here is more configuration from MongoDB:

rs0:PRIMARY> db.rocketchat_settings.find({ "_id" : "CDN_PREFIX"})
> { "_id" : "CDN_PREFIX", "value" : "" }
rs0:PRIMARY> db.rocketchat_settings.find({ "_id" : "Site_Url"})
> { "_id" : "Site_Url", "value" : "https://domain.com/chat", "type" : "string", "i18nDescription" : "Site_Url_Description", "public" : true, "group" : "General", "packageValue" : "http://localhost:3000", "valueSource" : "packageValue", "hidden" : false, "blocked" : false, "sorter" : 1, "i18nLabel" : "Site_Url", "autocomplete" : true, "ts" : ISODate("2018-07-13T19:31:01.211Z"), "_updatedAt" : ISODate("2018-07-13T19:31:01.211Z") }

I also tried updating these values CDN_PREFIX and Site_Url, and changing around the nginx config but nothing helps. Has anyone managed to get Docker+nginx+sudomain combination working?

P.S. I've read through #2655, #4546, #8487 and none of these provide a solution.
Also I read https://rocket.chat/docs/installation/manual-installation/running-in-a-sub-folder/
and https://rocket.chat/docs/installation/manual-installation/configuring-ssl-reverse-proxy/

@angusvb
Copy link

angusvb commented Jul 16, 2018

For me this works:

        location /rocketchat {
            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_pass http://127.0.0.1:3000/rocketchat;
            proxy_redirect off;
        }

@angusvb
Copy link

angusvb commented Jul 16, 2018

And my docker-compose.yml

db:
  image: mongo
  volumes:
    - ./data/runtime/db:/data/db
    - ./data/dump:/dump
  command: mongod --smallfiles

rocketchat:
  image: rocketchat/rocket.chat:latest
  environment:
    - MONGO_URL=mongodb://db:27017/rocketchat
    - ROOT_URL=https://127.0.0.1/rocketchat/
    - Accounts_UseDNSDomainCheck=False
  links:
    - db:db
  ports:
    - 3000:3000

@olegberman
Copy link
Author

Thank you @angusvb! Will try this.

@olegberman
Copy link
Author

@angusvb Thank you, this worked for the most part. I had to also add:

	location /file-upload/ {
           proxy_pass http://127.0.0.1:3000/chat/file-upload/;
        }

into the Nginx config to get file uploads working properly (and to not further modify Rocket chat's code).

@angusvb
Copy link

angusvb commented Jul 24, 2018

@olegberman thx, that is the part that I was still figuring out!

@olegberman
Copy link
Author

olegberman commented Jul 24, 2018

@angusvb can you confirm you're also having this issue integrating Zapier? #11509

@edwardando
Copy link

@angusvb thanks for posting your config, got me off the ground!

@sopheck
Copy link

sopheck commented Mar 24, 2023

@angusvb This saved my day, thanks a lot for sharing! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants