Nginx配置二级目录反向代理SpringMvc WebService,生成的报文丢失Nginx的location地址,寻求解决办法
Nginx配置
server {
listen 8082;
server_name localhost;
location /web/ {
proxy_pass http://127.0.0.1:8081/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_redirect off;
}
}
报文内容
不要在“proxy_pass”加路径。
If proxy_pass is specified without a URI, the request URI is passed to the server in the same form as sent by a client when the original request is processed, or the full normalized request URI is passed when processing the changed URI
nginx在配置proxy_pass的时候,URL结尾加斜线(/)与不加的区别和注意事项
proxy_pass URL结尾以 “/“ 结尾,表示是绝对根路径,location中匹配到的部分路径,nginx不会把它代理走;
如果不以“/”结尾,则location中匹配到的部分路径,也会被代理走