Nginx负载平衡不适用于测试AWS服务器

时间:2018-08-23 23:00:40

标签: nginx load-balancing

我有亚马逊树EC2实例:

我已经在两个实例中安装了Apache2

还有一个实例中的nginx。

我已经将我的nginx配置为:

ubuntu@ip-172-31-83-82:/etc/nginx$ cat nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
     upstream lbmysite {
        server ec2-34-238-244-237.compute-1.amazonaws.com;
        server ec2-54-144-235-129.compute-1.amazonaws.com;
     }

    server {
        location / {
            proxy_pass http://lbmysite;
        }
    }
}

$ sudo service nginx restart

但是当我执行时:

ubuntu@ip-172-31-83-82:/etc/nginx$ curl http://lbmysite
curl: (6) Could not resolve host: lbmysite

如果我愿意

curl ec2-34-238-244-237.compute-1.amazonaws.com

 _            _
| |_ ___  ___| |_
| __/ _ \/ __| __|
| ||  __/\__ \ |_
 \__\___||___/\__|

在所有教程中,人们都有相同的说明。

或在以下位置配置:/etc/nginx/conf.d

但这对我不起作用,我将相同的nginx.conf复制到了该路径

cp nginx.conf /etc/nginx/conf.d

sudo service nginx restart

我的问题是什么? :(

1 个答案:

答案 0 :(得分:0)

lbmysite声明为上游不会影响DNS解析,因此,如果您使用服务器IP,则应该能够ping通。

也许您错过了listen块内的server指令,这可能意味着您NGINX没有监听任何端口。尝试添加如下内容:

server {
  # Other stuff
  listen 80;
}

这样,NGINX将侦听默认的HTTP 80端口。

相关问题