如何覆盖nginx位置设置以自定义特定案例的配置?

时间:2018-02-21 10:33:59

标签: nginx reverse-proxy

我有一个Nginx位置配置,以匹配api请求网址,如下所示

location ~ /api/(.*) {
         rewrite /api/(.*) /$1 break;
         proxy_pass        http://localhost:8082;
         proxy_set_header  X-Real-IP  $remote_addr;
         proxy_set_header  Host $http_host;
}

现在,我想将特定网址自定义为/api/webscraper/(.*),以便使用端口 8083

的不同代理
location ~ /api/webscraper/(.*) {
         rewrite /api/(.*) /$1 break;
         proxy_pass        http://localhost:8083;
         proxy_set_header  X-Real-IP  $remote_addr;
         proxy_set_header  Host $http_host;
}

我知道后面的位置网址也与之前的位置模式匹配,因此当我向/api/webscraper/(.*)请求时,它始终转发到代理端口 8082 而不是我期望的 8083

那么,对于这个特定情况,我怎么能优先考虑以前的设置?我只是认为位置设置的顺序可能提供了一种重写但交换位置设置顺序对我不起作用。

0 个答案:

没有答案