Nginx反向代理location与proxy_pass配置规则总结
server { listen 8081; server_name localhost; location / { root html; index index.html index.htm; } #情景1:proxy_pass后有/ ,表绝对路径,不把匹配部分加入最终代理路径(location 和proxy_pass结尾一致) #访问地址:http://localhost:8081/WCP.Service/wcp/modeladapter/download/asc.shtml #最终代理:http://10.194.171.7:13082/modeladapter/download/asc.shtml location /WCP.Service/wcp/modeladapter/download/ { proxy_pass http://10.194.171.7:13082/modeladapter/download/; } #访问地址:http://localhost:8081/model/asc.shtml #最终代理:http://127.0.0.1:8082/model/asc.shtml location /model/ { proxy_pass http://127.0.0.1:8082/model/; } #情景2:proxy_pass后有/ ,表绝对路径,不把匹配部分加入最终代理路径(location 和proxy_pass结尾不一致) #访问地址:http://localhost:8081/model/asc.shtml #最终代理:http://127.0.0.1:8082/asc.shtml location /model/ { proxy_pass http://127.0.0.1:8082/; } #情景3:proxy_pass后没有 / ,Nginx会把匹配部分带到代理的url #访问地址:http://localhost:8081/model/asc.shtml #最终代理:http://127.0.0.1:8082/model/asc.shtml location /model/ { proxy_pass http://127.0.0.1:8082; } #情景4 #访问地址:http://localhost:8081/model/asc.shtml #最终代理:http://127.0.0.1:8082/AAAmodel/asc.shtml location /model/ { proxy_pass http://127.0.0.1:8082/AAA; } #情景5 #访问地址:http://localhost:8081/model/asc.shtml #最终代理:http://127.0.0.1:8082/asc.shtml location /model { proxy_pass http://127.0.0.1:8082/; } #情景6 #访问地址:http://localhost:8081/modelBBB/asc.shtml #最终代理:http://127.0.0.1:8082/asc.shtml location /model { proxy_pass http://127.0.0.1:8082/; } location /opus-front-sso { proxy_pass http://10.194.170.94/opus-front-sso; } location /awater { proxy_pass http://10.194.170.94/awater; } }
https://blog.csdn.net/m0_67391121/article/details/126113725