nginx - 如何使用 Docker Compose 启动 2 个(或更多)Rocket.Chat 实例?

标签 nginx docker amazon-ec2 docker-compose rocket.chat

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

我想做的有点像以下:

  • www.example1.comchat.example1.com 上聊天吗? ;
  • www.example2.comchat.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 实例时,一切都很顺利,但是有了更多实例,事情就会变得困惑。我是 尝试将以下端口附加到每个实例:
    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 中初始化,因此更改属性 ports在 docker-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:3002 代替 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;
      }
    }
    

    docker
    [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  | ➔ +-------------------------------------------------+
    

    最佳答案

    Docker 上的 Rocket.Chat 始终在端口 3000 上运行.所以你需要更改文件/var/www/chat.example2.com/docker-compose.yml为了绑定(bind)主机端口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
    ...
    

    关于nginx - 如何使用 Docker Compose 启动 2 个(或更多)Rocket.Chat 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39427907/

    相关文章:

    docker - 使用 docker-compose.yml 中的卷构建

    c++ - 远程 lldb 调试器进入 docker 容器的问题

    amazon-ec2 - Redis集群创建副本绑定(bind)公网IP

    tomcat - 监控 Tomcat Web 应用程序

    node.js - 配置 nginx-ingress 在字节到达时将其转发到底层 HTTP 服务

    c - nginx c 模块 hello world 不起作用

    java - 无法从 Java 连接到在 Docker 中运行的 Kafka

    linux - 如何让ec2实例长时间停止

    Nginx 在经过身份验证的页面后面提供静态内容

    Docker 1.12 集群模式和容器卷