我正在开发一些在同一个Amazon EC2实例(AWS EC2实例)下可用的项目,并且我正在尝试为每个项目创建Rocket.Chat。请注意,这些项目中的每一个都有自己的用户库,完全与其他项目隔离,因此每个Rocket.Chat实例也应该被隔离。
我想做的事情有点像:
www.example1.com
在chat.example1.com
; www.example2.com
在chat.example2.com
; 请记住,www.example1.com
,www.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实例时,Everythings一切正常,但是有更多实例会让人感到困惑。我尝试将以下端口附加到每个实例:
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中根据它自己的输出进行初始化,因此更改docker-compose.yml文件中的属性ports
似乎不起作用。我是否误解了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:3002
而不是chat.example2.com
,但后者更合适。
注意:出于教学和隐私的原因,我已将所有内容更改为使用chat.example1.com和chat.example2.com,希望您不要错。如果事情让你感到困惑,请告诉我,以便检查是否有错误,拼写错误或提供更多信息。此外,请随意为此问题提出更好的解决方法。
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
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
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;
}
}
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
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 | ➔ +-------------------------------------------------+
答案 0 :(得分:2)
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
...