【发布时间】:2021-12-11 07:02:24
【问题描述】:
想知道是否有办法将我的 nginx.conf 文件配置为使用正则表达式来匹配位置块中的代理 url,然后还使用正则表达式作为 proxypass url。当我有一个静态路径时,我的设置当前工作正常,但我想扩展它以使用 2 种或更多类似如下。原文是:
location /pacs-1/ {
auth_request /auth;
auth_request_set $auth_status $upstream_status;
proxy_buffering off;
rewrite /pacs-1/(.*) /$1 break;
proxy_pass http://pacs-1:8042;
proxy_redirect http://pacs-1:8042/ /;
我想做类似以下的事情,这显然不起作用(即(?:pacs-butterfly|pacs-1|pacs-2))。对于代理通行证,我需要使用从位置块匹配的任何路径进行代理重写和代理通行证/重定向。不确定有没有办法做到这一点。
location /(pacs-butterfly|pacs-1|pacs-2)/ { #match any of those in ()
. . . not sure how to code what I show below.
auth_request /auth;
auth_request_set $auth_status $upstream_status;
proxy_buffering off;
rewrite /(?:pacs-butterfly|pacs-1|pacs-2)/(.*) /$1 break;
proxy_pass http://(?:pacs-butterfly|pacs-1|pacs-2):8042;
proxy_redirect http://(?:pacs-butterfly|pacs-1|pacs-2):8042/ /;
【问题讨论】:
标签: regex nginx config nginx-reverse-proxy