NGINX - 错误 502,除非设置 User-Agent header

NGINX - Error 502 unless User-Agent header is set

我对 NGINX 有一个非常奇怪的问题。

我们根据 URL 路由到不同的服务器。这一切都很好。使用浏览器,一切正常。

奇怪的是,当我尝试从工具(如 Postman、Insomnia、Curl 等)向 API 发出 GET 请求时,如果 User-Agent header没有欺骗浏览器,我收到 502 Bad Gateway 错误。

为什么会这样?我需要从另一个 back-end 以编程方式调用此 API,但我必须设置 User-Agent header 否则它将失败。 (将 user-agent 设置为 "curl" 浏览器不起作用)

这是我的 NGINX 配置

    server {
        listen 443 ssl;
        server_name 10.10.10.10;
        ssl_certificate /https/10.10.10.10.crt;
        ssl_certificate_key /https/10.10.10.10.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!MD5;

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

        location /abc {
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Frame-Options SAMEORIGIN;
                proxy_pass http://10.3.0.2:80;
        }

        location /def {
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Frame-Options SAMEORIGIN;
                proxy_pass http://10.3.0.3:80;
        }
}

来自浏览器的请求完全正常。

Insomnia 的请求带有 User-Agent 欺骗(效果很好!)

Insomnia 的请求没有 User-Agent 欺骗(错误 502!?)

谢谢!

对不起。找到了。我这边的菜鸟错误!完全不是nginx的问题。

如果用户不在 Chrome,Flask 服务器实际上有一行来提供 "change your browser" 消息,以避免浏览器兼容性问题。不幸的是,browser_splash 文件已被删除,因此在这种情况下它没有提供任何服务。没有注意到这已提交:

if request.user_agent.browser != 'chrome':
  return render_template('browser_splash.html')