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俱乐部。