4

I'm developing some projects that are available under the same Amazon EC2 instance (AWS EC2 instance) and I'm trying to create a Rocket.Chat for each of these projects. Note that each of these projects has it's own userbase and is completely isolated from others, thus each Rocket.Chat instance should be isolated too.

What I want to do is somewhat like the following:

  • www.example1.com has it's chat at chat.example1.com;
  • www.example2.com has it's chat at chat.example2.com;
  • And so on...

Remember that www.example1.com, www.example2.com (...) are hosted in the same EC2 instance. This instance has a Nginx server that serves these sites. So you can imagine that I have the following architecture:

# Sites content
  /var/www/www.example1.com/
     index.php
     (...)

  /var/www/www.example2.com/
     index.php
     (...)

# Chats content
  /var/www/chat.example1.com/
    data/
    docker-compose.yml
    (...)

  /var/www/chat.example2.com/
    data/
    docker-compose.yml
    (...)

# Nginx config
/etc/nginx/sites-enabled/www_example1_com
/etc/nginx/sites-enabled/www_example2_com
/etc/nginx/sites-enabled/chat_example1_com
/etc/nginx/sites-enabled/chat_example2_com

Everythings was going fine while I have a single Rocket.Chat instance using Docker Compose, but with more instances things get confused. I'm trying to attach the following ports to each instance:

chat.example1.com
    db: 27017
    rocketchat: 3000
    hubot: 3001

chat.example2.com
    db: 27017
    rocketchat: 3002
    hubot: 3003

The things get weird when chat.example1.com works as expected, but chat.example2.com no. I've found that chat.example2.com is being initialized in port 3000 according to it's own output, therefore change the property ports in the docker-compose.yml file doesn't seems to be working. Did I misunderstood some key concepts from Docker Compose or it's really not working as expected?

If I try to access the sites, I got the following:

  • chat.example1.com -> works as expected.
  • chat.example1.com:3000 -> "Secure connection failed".
  • chat.example1.com:3002 -> Page never loads.
  • chat.example2.com -> Nginx shows up www.example2.com.
  • chat.example2.com:3000 -> Loads, but seems to be using chat.example1.com Rocket.Chat instance / database.
  • chat.example2.com:3002 -> Page never loads.

What's going on? What should I do in order to fix these problems and get as many Rocket.Chat instances as I want, each of them being provided in the URL I want? There's no problem in using ports explicitly to access chats (e.g: use chat.example2.com:3002 instead chat.example2.com, but the later is more desirable).



Below you can see the most relevant files.

Note: for didactic and privacy reasons I've changed everything to use chat.example1.com and chat.example2.com, hope you don't get it wrong. If things get confused to you, tell me so I check if there's a mistake, typo or give more info. Also, feel free to suggest a better approach for this problem.

/var/www/chat.example1.com/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://chat.example1.com/
    - Accounts_UseDNSDomainCheck=True
  links:
    - db:db
  ports:
    - 3000:3000

hubot:
  image: rocketchat/hubot-rocketchat:v0.1.4
  environment:
    - ROCKETCHAT_URL=chat.example1.com
    - ROCKETCHAT_ROOM=GENERAL
    - ROCKETCHAT_USER=Botname
    - ROCKETCHAT_PASSWORD=BotPassw0rd
    - BOT_NAME=Botname
    - EXTERNAL_SCRIPTS=hubot-help,hubot-seen,hubot-links,hubot-greetings
  links:
    - rocketchat:rocketchat
# this is used to expose the hubot port for notifications on the host on port 3001, e.g. for hubot-jenkins-notifier
  ports:
    - 3001:8080

/var/www/chat.example2.com/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=http://chat.example2.com/
    - Accounts_UseDNSDomainCheck=True
  links:
    - db:db
  ports:
    - 3002:3002

hubot:
  image: rocketchat/hubot-rocketchat:v0.1.4
  environment:
    - ROCKETCHAT_URL=chat.example2.com
    - ROCKETCHAT_ROOM=GENERAL
    - ROCKETCHAT_USER=Botname
    - ROCKETCHAT_PASSWORD=BotPassw0rd
    - BOT_NAME=Botname
    - EXTERNAL_SCRIPTS=hubot-help,hubot-seen,hubot-links,hubot-greetings
  links:
    - rocketchat:rocketchat
# this is used to expose the hubot port for notifications on the host on port 3001, e.g. for hubot-jenkins-notifier
  ports:
    - 3003:8080

/etc/nginx/sites-enabled/chat_example1_com:

server {
  listen 443 ssl;
  listen 80;
  server_name chat.example1.com;

  error_log /var/log/nginx/rocketchat_chat_example2_com_error.log;

  location / {
    proxy_pass http://chat.example1.com:3000/;
    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;
  }
}

/etc/nginx/sites-enabled/chat_example2_com:

server {
  listen 443 ssl;
  listen 80;
  server_name chat.example2.com;

  error_log /var/log/nginx/rocketchat_chat_example2_com_error.log;

  location / {
    proxy_pass http://chat.example2.com:3002/;
    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;
  }
}

Docker ps

[ec2-user@ ~]$ docker ps
CONTAINER ID        IMAGE                                COMMAND                  CREATED             STATUS              PORTS                              NAMES
2aa6bc690f0d        rocketchat/hubot-rocketchat:v0.1.4   "/bin/sh -c 'node -e "   16 hours ago        Up 16 hours         0.0.0.0:3003->8080/tcp             chatexample2com_hubot_1
eca85553211a        rocketchat/rocket.chat:latest        "node main.js"           16 hours ago        Up 16 hours         3000/tcp, 0.0.0.0:3002->3002/tcp   chatexample2com_rocketchat_1
5a0f5fda3b84        rocketchat/hubot-rocketchat:v0.1.4   "/bin/sh -c 'node -e "   17 hours ago        Up 17 hours         0.0.0.0:3001->8080/tcp             chatexample1com_hubot_1
a07149fd0e6e        rocketchat/rocket.chat:latest        "node main.js"           17 hours ago        Up 17 hours         0.0.0.0:3000->3000/tcp             chatexample1com_rocketchat_1
7ca3b1c3743f        mongo                                "/entrypoint.sh mongo"   18 hours ago        Up 17 hours         27017/tcp                          chatexample1com_db_1
f94d24c55b64        mongo                                "/entrypoint.sh mongo"   18 hours ago        Up 16 hours         27017/tcp                          chatexample2com_db_1

chat.example2.com init

rocketchat_1  | ➔ System ➔ startup
rocketchat_1  | ➔ +-------------------------------------------------+
rocketchat_1  | ➔ |                  SERVER RUNNING                 |
rocketchat_1  | ➔ +-------------------------------------------------+
rocketchat_1  | ➔ |                                                 |
rocketchat_1  | ➔ |       Version: 0.37.1                           |
rocketchat_1  | ➔ |  Process Port: 3000                             |
rocketchat_1  | ➔ |      Site URL: http://chat.example2.com:3000    |
rocketchat_1  | ➔ |                                                 |
rocketchat_1  | ➔ +-------------------------------------------------+
Paladini
  • 4,522
  • 15
  • 53
  • 96

1 Answers1

3

Rocket.Chat on Docker always runs on port 3000. So you need to change the file /var/www/chat.example2.com/docker-compose.yml in order to bind the host port 3002 to container port 3000, like this:

...
rocketchat:
  image: rocketchat/rocket.chat:latest
  environment:
    - MONGO_URL=mongodb://db:27017/rocketchat
    - ROOT_URL=http://chat.example2.com/
    - Accounts_UseDNSDomainCheck=True
  links:
    - db:db
  ports:
    - 3002:3000
...