Nginx 负载平衡无法测试 aws 服务器

Nginx load balancing does not work test aws servers

我有树亚马逊 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

我的问题是什么? :(

声明lbmysite为upstream不影响DNS解析,所以使用服务器IP应该能ping通

也许您在 server 块中错过了 listen 指令,这可能意味着您的 NGINX 没有监听任何端口。尝试像这样添加一些:

server {
  # Other stuff
  listen 80;
}

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