4

我正在开发一些在同一个 Amazon EC2 实例(AWS EC2 实例)下可用的项目,并且我正在尝试为每个项目创建一个Rocket.Chat 。请注意,这些项目中的每一个都有自己的用户群,并且与其他项目完全隔离,因此每个 Rocket.Chat 实例也应该隔离。

我想做的有点像以下:

  • www.example1.com有它在聊天chat.example1.com
  • www.example2.com有它在聊天chat.example2.com
  • 等等...

请记住www.example1.comwww.example2.com(...) 托管在同一个 EC2 实例中。这个实例有一个为这些站点提供服务的 Nginx 服务器。所以你可以想象我有以下架构:

# 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

当我有一个使用 Docker Compose 的 Rocket.Chat 实例时,一切都很顺利,但是有了更多实例,事情就会变得混乱。我正在尝试将以下端口附加到每个实例:

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

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

chat.example1.com按预期工作时,事情变得很奇怪,但chat.example2.com没有。我发现它chat.example2.com正在根据它自己的输出在端口 3000 中进行初始化,因此更改portsdocker-compose.yml 文件中的属性似乎不起作用。我是否误解了 Docker Compose 的一些关键概念,或者它真的没有按预期工作?

如果我尝试访问这些网站,我会得到以下信息:

  • chat.example1.com-> 按预期工作。
  • chat.example1.com:3000->“安全连接失败”。
  • chat.example1.com:3002-> 页面永远不会加载。
  • chat.example2.com-> Nginx 出现www.example2.com
  • chat.example2.com:3000-> 加载,但似乎正在使用 chat.example1.com Rocket.Chat 实例/数据库。
  • chat.example2.com:3002-> 页面永远不会加载。

这是怎么回事?我应该怎么做才能解决这些问题并获得尽可能多的 Rocket.Chat 实例,每个实例都在我想要的 URL 中提供?显式使用端口来访问聊天没有问题(例如:使用chat.example2.com:3002instead chat.example2.com,但后者更可取)。



您可以在下面看到最相关的文件。

注意:出于教学和隐私原因,我已将所有内容更改为使用 chat.example1.com 和 chat.example2.com,希望您不要误会。如果事情让您感到困惑,请告诉我,以便我检查是否有错误、拼写错误或提供更多信息。另外,请随意提出解决此问题的更好方法。

/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;
  }
}

泊坞窗

[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 初始化

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  | ➔ +-------------------------------------------------+
4

1 回答 1

3

Docker 上的 Rocket.Chat 总是在端口上运行3000。因此,您需要更改文件/var/www/chat.example2.com/docker-compose.yml以将主机端口绑定3002到容器端口3000,如下所示:

...
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
...
于 2016-09-12T17:02:59.703 回答