简体   繁体   English

docker nginx负载平衡不适用于Azure

[英]docker nginx load balancing not working with Azure

Ok been trying this setup for a full day now. 好的,现在已经尝试了一整天了。 I cannot get Nginx to connect the domain name that azure gave me to my node docker containers. 我无法让Nginx将azure给我的域名连接到我的node docker容器。

I'm using Azure to create a VM . 我正在使用Azure创建VM The DNS name is scout-1j013s34.cloudapp.net The virtual IP address is 191.237.66.86 DNS namescout-1j013s34.cloudapp.net virtual IP address191.237.66.86

I can ssh into the VM with ssh monty@scout-1j013s34.cloudapp.net -p 61777 . 我可以sshVMssh monty@scout-1j013s34.cloudapp.net -p 61777 I'm not sure why I need to specify a port? 我不确定为什么需要指定端口?

The VM is running Ubuntu 14.04 . VM正在运行Ubuntu 14.04 I installed docker myself. 我自己安装了docker

I found and followed the following tutorial A sample Docker workflow with Nginx, Node.js and Redis 我找到并遵循了以下教程A sample Docker workflow with Nginx, Node.js and Redis

I built, and ran the containers as shown below. 我构建并运行了容器,如下所示。

码头工人进程

Here is my nginx.conf file 这是我的nginx.conf文件

worker_processes 4;

events { worker_connections 1024; }

http {

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;


    upstream node-app {
          least_conn;
          server node1:1337 weight=10 max_fails=3 fail_timeout=30s;
          server node2:1337 weight=10 max_fails=3 fail_timeout=30s;
          server node3:1337 weight=10 max_fails=3 fail_timeout=30s;
    }

    server {
          listen 80;

              server_name 191.237.66.86 scout-1j013s34.cloudapp.net www.scout-1j013s34.cloudapp.net;

          location / {
            proxy_pass http://node-app;
            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;
          }
    }
}

when I enter http://scout-1j013s34.cloudapp.net/ into the browser address bar, it times out. 当我在浏览器地址栏中输入http://scout-1j013s34.cloudapp.net/时,它超时了。

Update: I have EXPOSE 1337 in my Dockerfile to expose the 1337 ports for each node container. 更新:我有EXPOSE 1337在我Dockerfile揭露1337个端口,每个节点的容器。

For each node container I ran docker run -it --name node1 --link mongo:MONGODB -v /home/monty/scout/backend-api/:/scout-sails mlennie/scout-sails bash changing the name to node2 and node3 for the next 2 then I went into each container and started the sails.js app with sails lift . 对于每个节点容器,我都docker run -it --name node1 --link mongo:MONGODB -v /home/monty/scout/backend-api/:/scout-sails mlennie/scout-sails bash将名称更改为node2并接下来的2个node3,然后我进入每个容器,并用sails.js sails lift启动了sails.js应用程序。

Then I started the nginx container and linked it to the 3 node containers with the command docker run -d --name nginx -p 80:80 --link node1:node1 --link node2:node2 --link node3:node3 mlennie/nginx 然后我启动了nginx容器,并使用命令docker run -d --name nginx -p 80:80 --link node1:node1 --link node2:node2 --link node3:node3 mlennie/nginx将其链接到3个节点容器docker run -d --name nginx -p 80:80 --link node1:node1 --link node2:node2 --link node3:node3 mlennie/nginx

好的,我可以正常工作了,我需要通过Azure管理门户手动添加一个端口为80的终结点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM