想知道是否有一种方法可以将我的nginx.conf文件配置为使用regex来匹配位置块中的代理url,然后对proxypass url也使用regex。当我有一个静态路径时,我的设置当前工作得很好,但是我想将其扩展到使用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-蝶形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/ /;发布于 2021-12-10 23:02:24
看来您错过了Regex匹配的~。可以添加括号以捕获$n格式的变量,$request_uri也可用:
location ~ ^/(pacs-butterfly|pacs-1|pacs-2)(/.*) {
default_type text/plain;
return 200 "
$1
$2
$request_uri
$args
";
}$ curl "https://example.com/pacs-1/foo/bar?name=value&foo=bar"
pacs-1
/foo/bar
/pacs-1/foo/bar?name=value&foo=bar
name=value&foo=barhttps://stackoverflow.com/questions/70310951
复制相似问题