请教,nginx代理配置问题

#后端接口代理
server {
    listen       80;
    charset utf-8;
    #设置反向代理,凡是访问地址带rest的都进入到这里
    location /abc {
        proxy_pass http://test.com/;
    }
}

需求是这样的,本地访问地址中有/abc的都做代理转发,例如访问http://localhost/abc/1/会请求http://test.com/abc/1/,即访问http://localhost/abc/··/都会进入http://test.com/abc/··/,这样的规则要怎么写?有尝试过的吗?请大神帮看下,万分感谢!!!

阅读 1.9k
2 个回答
location ^~ /abc {
    proxy_pass http://test.com/;
}
location ^~ /abc {
    proxy_pass http://test.com/$request_uri;
} 

使用上面代码解决了,感谢上面的兄弟。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题