nginx反向代理配置去除前缀问题
nginx反向代理配置去除前缀问题
两种方案一种,自动拼接前缀,第二种是替换前缀;
比如:
前端服务器url为:https://114.114.114.114:8002/myqz/menu/index.html
后台服务器地址为:http://127.0.0.1:9008
第一种方式:
自动拼接前缀,前端服务器地址为:https://114.114.114.114:8002/menu/index.html
location ~ \.do$ {
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_pass http://127.0.0.1:9008;
}
location ~ ^/(.*)$ {
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_pass https://114.114.114.114:8002/myqz/$1?$args;
}
第二种方式:
替换前缀 ,前端服务器地址为:https://114.114.114.114:8002/myqz/menu/index.html
location / {
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_pass https://114.114.114.114:8002;
}
location ~ \.do$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
rewrite ^/myqz/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:9008;
}
更多推荐
所有评论(0)