nginx重写路径转发
最近项目遇到根据nginx根据目录进行转发,经过查阅资料及不断尝试终于完成,特此自己记录下,给有需要的朋友参考。浏览器请求路径为:http://localhost/{passid}/{cid}/api/oa/index.html,其中passid及cid是可变项用于前端通过url获取作为参数传给后端。api为固定项,用于nginx做及目录转发。实际访问uri为:http://localhost/o
·
最近项目遇到根据nginx根据目录进行转发,经过查阅资料及不断尝试终于完成,特此自己记录下,给有需要的朋友参考。
浏览器请求路径为:http://localhost/{passid}/{cid}/api/oa/index.html,其中passid及cid是可变项用于前端通过url获取作为参数传给后端。api为固定项,用于nginx做及目录转发。实际访问uri为:http://localhost/oa/index.html。所以nginx转发需求为:http://localhost/{passid}/{cid}/api/oa/index.html -> http://localhost/oa/index.html
server {
listen 80;
server_name localhost;
location ~ /api/ {
proxy_pass http://127.0.0.1:9996;
#root html;
#index index.html index.htm;
#rewrite_log on;
rewrite "^/(.*)/api\/(.*)$" /$2 break;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
更多推荐
所有评论(0)