【发布时间】:2020-06-02 18:51:05
【问题描述】:
我对 NGINX 有一个非常奇怪的问题。
我们根据 URL 路由到不同的服务器。这一切都很好。使用浏览器,一切都很好。
奇怪的是,当我尝试从工具(如 Postman、Insomnia、Curl 等)向 API 发出 GET 请求时。如果 User-Agent 标头未欺骗浏览器,我会收到 502 Bad网关错误。
为什么会这样?我需要从另一个后端以编程方式调用此 API,但我必须设置 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 的请求,没有欺骗用户代理(错误 502!?)
- 注意:我在此请求中设置 cookie,因为它们由后端的服务器使用。不确定这是否与用户代理问题有关...
谢谢!
【问题讨论】:
标签: http nginx cookies http-headers user-agent