当涉及到负载均衡器时,我对Nginx的配置感到有点困惑。
这就是我的处境。
在亚马逊网络服务上,我有一个负载均衡器来控制2个ec2实例的流量。
Nginx的默认配置运行良好,事实上,如果我在浏览器中直接打开ec2实例IP,我会看到nginx页面。同样,如果我点击负载均衡器dns名称,我会看到nginx默认页面。
用于演示目的。我的nginx.conf配置如下:
server {
listen 80; ## listen for ipv4; this line is default and implied
listen vm-ip:80;
server_name vm-ip;
root /usr/share/nginx/html;
index index.html;
server_tokens off; # disable the Server nginx header
# enable gzip
gzip on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
image/svg+xml;
location / {
# try_files $uri /index.html; # redirect all request to index.html
proxy_pass https://<dns of website I want to be redirected to>;
}
}我为两个ec2实例设置了相同的nginx.conf。完成此配置后,我尝试直接访问ec2实例的ip,并被正确地重定向到我想要的网站。但问题是,当我尝试在浏览器中打开负载均衡器时,我仍然看到nginx默认页面。
有没有人能解释一下,我到底做错了什么?
如果我的问题不够清楚,请向我询问更多信息,我将非常乐意提供答案。
提前谢谢你
发布于 2021-11-25 14:25:47
问题解决了。问题出在server_name,我不得不将它指向负载均衡器A记录。
https://stackoverflow.com/questions/70101366
复制相似问题