我试图使用包含空格的参数调用GET api:
https://abc.xyz/search/web/buildings/search/v2/city/new%20york端点命中负载均衡器(nginx),后者将请求重定向到合适的机器。
在响应中,我得到了505 HTTP版本不支持的错误。但是,当我使用HTTP (使用内部IP)向负载均衡器发出相同的请求时,它成功地返回响应。
以下是这两种情况的相关访问日志:
通过http调用nginx的访问日志
"GET /search/web/buildings/search/v2/city/r%20c HTTP/1.1" S=200 487 T=0.005 R=- 10.140.15.199通过http调用时机器的访问日志
"GET /search/search/web/buildings/search/v2/city/r%20c HTTP/1.0" 200 36上述要求运作良好。但是,当我们通过https请求时,机器中的请求就不同了(应该是d%20a而不是d a)。
通过https调用nginx的访问日志
"GET /search/web/buildings/search/v2/city/d%20a HTTP/1.1" S=505 168 T=0.001 R=- 35.200.191.89通过https调用时机器的访问日志
"GET /search/search/web/buildings/search/v2/city/d a HTTP/1.0" 505 -下面是相关的nginx配置:
upstream searchtomcat {
least_conn;
server search-1:8080;
server search-2:8080;
}
server {
#listen 443 ssl http2;
listen 443;
client_max_body_size 100M;
...
location ~* ^/search/(.*)$ {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://searchtomcat/search/search/$1;
proxy_read_timeout 900;
}
}在error.log中什么都没有。
机器以不同的方式接收请求的原因可能是什么?
发布于 2018-10-05 20:10:13
整个issue.is之所以发生,是因为你的URL中的空间正在被发送给tomcat。因此,a被解释为HTTP代码,而不是HTTP/1.0。解决额外的空间问题将解决问题。
在rewrite块中使用location{}可以解决这一问题。
location /search/ {
rewrite ^/search(/.*) /search/search$1 break;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://searchtomcat;
proxy_read_timeout 900;
}另外,对于http和https服务器有不同的配置,请查看http服务器。那个似乎是正确的。
发布于 2022-09-11 01:16:08
当我试图在nginx上设置端口转发时,我得到了505秒。
对我来说,解决方案是将这一行添加到包含proxy_pass指令的proxy_pass块中:
proxy_http_version 1.1;在这个主题上,我能找到的最接近文档的是这里。
https://stackoverflow.com/questions/52661688
复制相似问题