配置1,主机报头替换:
location /phpinfo {
proxy_set_header Host $host;
proxy_pass http://localhost:8000;
}
curl -s -o /dev/null -D - http://192.168.56.102/phpinfo
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sun, 21 Jun 2020 13:12:05 GMT
Content-Type: text/html; charset=iso-8859-1
Content-Length: 323
Connection: keep-alive
Location: http://192.168.56.102:8000/phpinfo/配置2只需proxy_pass:
location /phpinfo {
proxy_pass http://localhost:8000;
}
curl -s -o /dev/null -D - http://192.168.56.102/phpinfo
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sun, 21 Jun 2020 13:25:15 GMT
Content-Type: text/html; charset=iso-8859-1
Content-Length: 313
Location: http://192.168.56.102/phpinfo/
Connection: keep-alive摘要: Linux localhost 5.4.47-0-virt #1-高山SMP清华,18 Jun 2020 14:54:31 UTC x86_64 Linux nginx版本: nginx/1.18.0
如果未定义尾部斜杠,则具有主机标头替换的proxy_pass将重定向到:
http://192.168.56.102:8000/phpinfo/期望值:
Location: http://192.168.56.102/phpinfo/这是一个特性吗?如何解决这个问题?
发布于 2020-06-22 13:52:55
此行为是由后端服务器(apache2)引起的。当uri末尾没有斜杠时,它返回重定向301。因此,有两种解决方案:
位置/{ proxy_set_header主机$host;proxy_redirect http://$host:8000/ /;proxy_pass http://localhost:8000;
}
https://stackoverflow.com/questions/62499295
复制相似问题