NGINX如何将变量从服务器名称传递到代理服务器?

NGINX如何将变量从服务器名称传递到代理服务器?,nginx,Nginx,目前,我有如下工作nginx配置: server { listen 80; server_name stage.mysite.eu; location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection

目前,我有如下工作nginx配置:

server {
    listen 80;
    server_name stage.mysite.eu;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
但我希望更改上述配置以支持url中的动态端口,例如:

port-3001.stage.mysite.eu->http://localhost:3001

port-3002.stage.mysite.eu->http://localhost:3002

我尝试过配置,但没有成功:

server {
    listen 80;
    server_name ~^port-(?<portNumber>.+)\.stage\.mysite\.eu$;

    location / {
        proxy_pass http://localhost:$portNumber;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
服务器{
听80;
服务器名称^端口-(?。+)\.stage\.mysite\.eu$;
地点/{
代理通行证http://localhost:$portNumber;
proxy_http_版本1.1;
代理设置头升级$http\U升级;
代理集头连接“升级”;
代理设置头主机$Host;
代理缓存绕过$http\u升级;
}
}
如何更改上述配置以支持我的需求