【发布时间】:2021-02-06 13:04:19
【问题描述】:
我有以下 nginx 配置:
location ~* ^/path/(.*) {
set $query $1;
proxy_pass http://backend_app/$query;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
}
我希望 nginx 将请求从 http://frontend/path/subpath name 代理到 http://backend_app/subpath name。但我看到了一些奇怪的行为:
http://frontend/path/subpath --> http://backend_app/path/subpath 工作正常。
但是
http://frontend/path/subpath name --> 返回 400 错误请求,错误消息如下:
< HTTP/1.1 400 Bad Request
< Server: nginx/1.16.1
< Date: Sat, 06 Feb 2021 01:13:15 GMT
< Content-Type: text/html
< Content-Length: 198
< Connection: keep-alive
< Strict-Transport-Security: max-age=31536000; includeSubDomains
<
<html>
<head>
<title>Bad Request</title>
</head>
<body>
<h1><p>Bad Request</p></h1>
Invalid HTTP Version 'Invalid HTTP Version: 'name HTTP/1.0''
</body>
</html>
* Connection #0 to host frontend left intact
* Closing connection 0
请注意响应中的错误消息为Invalid HTTP Version &#x27;Invalid HTTP Version: &#x27;name HTTP/1.0&#x27;&#x27;
所以 nginx 将路径中空格后面的单词解释为 http 版本名称的一部分。
我也尝试过使用 URL 编码,但仍然没有成功。
【问题讨论】:
标签: nginx nginx-reverse-proxy nginx-location