nginx转发移除上下文(去掉匹配路径)方法

1、location和proxy_pass都带/去除

http://api/ 的 api后面带/, 则会移除api这个上下文

location ^~/api/ {
    proxy_pass http://api/;
}

2、rewrite去除

http://api 的 api后面不带/, 通过rewrite移除api这个上下文

location ^~/api/ {
    rewrite ^/api/(.*)$ /$1 break;
    proxy_pass http://api;
}

Categories: 系统运维