Nginx反向代理location与proxy_pass配置规则总结
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | 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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示