IT俱乐部 Nginx Nginx反向代理的location路径映射方式

Nginx反向代理的location路径映射方式

1、转发路径以端口结尾不添加根路径的情况

请求:

1
http://127.0.0.1/appStore/api/getTest

以下全部基于此请求进行映射说明,红色为推荐配置

配置1:

只替换到端口的那一部分

1
2
3
4
5
location ^~ /appStore {
 
    proxy_pass   http://127.0.0.1:9222;
 
}

实际:

1
http://127.0.0.1:9222/appStore/api/getTest

配置2:

1
2
3
4
5
location ^~ /appStore/ {
 
    proxy_pass   http://127.0.0.1:9222;
 
}

实际:

1
http://127.0.0.1:9222/appStore/api/getTest

配置3:

替换到标识的路径部分

1
2
3
4
5
location ^~ /appStore {
 
    proxy_pass   http://127.0.0.1:9222/;
 
}

实际:

1
http://127.0.0.1:9222//api/getTest

配置4:

1
2
3
4
5
location ^~ /appStore/ {
 
    proxy_pass   http://127.0.0.1:9222/;
 
}

实际:

1
http://127.0.0.1:9222/api/getTest

2、转发路径以端口结尾添加根路径的情况 

请求:

1
http://127.0.0.1/appStore/api/getTest

配置1:

替换到标识的路径部分

1
2
3
4
5
location ^~ /appStore {
 
    proxy_pass   http://127.0.0.1:9222/appStore;
 
}

实际:

1
http://127.0.0.1:9222/appStore/api/getTest

配置2:

1
2
3
4
5
location ^~ /appStore/ {
 
    proxy_pass   http://127.0.0.1:9222/appStore;
 
}

实际:

1
http://127.0.0.1:9222/appStoreapi/getTest

配置3:

1
2
3
4
5
location ^~ /appStore {
 
    proxy_pass   http://127.0.0.1:9222/appStore/;
 
}

实际:

1
http://127.0.0.1:9222/appStore//api/getTest

配置4:

1
2
3
4
5
location ^~ /appStore/ {
 
    proxy_pass   http://127.0.0.1:9222/appStore/;
 
}

实际:

1
http://127.0.0.1:9222/appStore/api/getTest

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持IT俱乐部。

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/server/nginx/12710.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部