google-chrome - Chrome ignores Nginx upstreams (loads only first)
问题描述
I have simple setup of 3 servers (in containers) - 2 "app" servers (whoami services - so by response I can acknowledge server) and nginx server.
I've launched nginx with simple load-balancing configuration:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
upstream myapp1 {
server w1:8000 weight=1;
server w2:8000 weight=1;
}
server {
listen 80;
location / {
proxy_pass http://myapp1/;
}
}
}
The problem is that it doesn't work in Chrome - it always loads only first server. I've tried to turn off cache in Dev console + reload via CTRL+F5 but nothing helped.
If I try to curl
nginx server - I get responses in round robin manner (as expected).
Here is my containers setup:
docker network create testnw
docker run -dit --name w1 --network testnw jwilder/whoami # app1
docker run -dit --name w2 --network testnw jwilder/whoami # app2
docker run -dit --name ng --network testnw -p 8989:80 -v ${PWD}/my.conf:/etc/nginx/nginx.conf nginx # LB server
curl localhost:8989 # will get response from w1
curl localhost:8989 # will get response from w2
curl localhost:8989 # will get response from w1
...
解决方案
编辑 3:发现了一个有趣的问题。在 Chrome 中,每次我访问我的网站时,它都会进行两次调用,无论它们被调用到我的网站/我的网站和我的网站的 /favicon.ico。我没有/favicon.ico。我认为正在发生的事情
- 当 Nginx 收到我网站的请求时,它正在上游加载第一台服务器。
- 当 chrome 从我的网站加载 / 时,它还会调用我网站的 /favicon.ico,这会导致对 Nginx 进行新的调用,因此它会从上游的下一个服务器加载 .ico 文件。
- 发生这种情况时,服务器 1、2、3 按顺序加载 1(来自 2 的 ico 文件)、3(来自 1 的 ico 文件)、2(来自 3 的 ico 文件)。并循环重复。
一旦我停止在 Nginx 中加载 /favicon.ico,我的三个上游服务器 1、2、3 将按循环的 1、2、3 顺序加载。
我把它放在带有上游的服务器中,以禁用从 Nginx 加载 favicon.ico。
location = /favicon.ico {
log_not_found off;
}
希望任何有这个问题的人都觉得这很有用。
编辑 2:找出问题所在,负载平衡在 Nginx conf 文件中的静态文件和静态服务器上运行良好。但是我的应用程序正在由节点加载,因此必须在启动所有节点服务器后启动 Nginx。当我在 Nginx 运行时重新启动应用程序服务器时,问题再次出现。现在没有问题会很快更新
编辑1:这对我来说不再有效,昨天有效,今天继续使用相同的配置,问题再次出现。
我的设置也有同样的问题。经过大量代理设置、VirtualBox 设置和网络编辑后,什么对我有用。
在 HTTP 块中添加一个额外的服务器块。
server{
}
并重新加载 Nginx 服务。
它对我有用,在 chrome 和 firefox 按给定顺序加载服务器后重新加载后,我删除了服务器块,它仍在工作。
不知道为什么首先提出这个问题。希望这有助于解决您的问题。
推荐阅读
- python - Matplotlib imshow 具有不断变化的数据范围的棋盘图
- html - 以html形式分配制表顺序
- node.js - 使用 NodeJS 将大表从流式传输到另一个表
- lxc - 如何向 LXC 容器添加功能
- sql - SQL JOIN 同一张表
- javascript - 变量上的替换()不起作用
- swift - 尝试以正确的方式处理错误和可选项
- wordpress - 添加新站点时出现 Wordpress 多站点错误
- machine-learning - 为什么 ID3 算法不适用于 Weka 中的 UCI Mushroom 数据集?
- python - 使用 Python 在网站上查找特定名称