1. location和proxy_pass都带/去除
location ^~/api/ { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; proxy_pass http://api/; }
http://api/ 的 api后面带/, 则会移除api这个上下文
2. rewrite去除
location ^~/api/ { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; rewrite ^/api/(.*)$ /$1 break; proxy_pass http://api; }
http://api 的 api后面不带/, 通过rewrite移除api这个上下文
3. location带/, proxy_pass不带上下文去除
# 转发示例: # 请求:http://aaa.com/system/path/request # 转发:http://bbb.com/path/request # location ^~ /system/ { proxy_pass http://bbb.com; }
保留
1. location不带/, proxy_pass不带上下文保留
# 转发示例 # 请求:http://aaa.com/system/path/request # 转发:http://bbb.com/system/path/request # location ^~ /system { proxy_pass http://bbb.com; }