NGINX 将位置指令附加到 proxy_pass url?

NGINX 将位置指令附加到 proxy_pass url?

我的 nginx.conf

location /admin/ {
                proxy_buffering off;
                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;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass https://myproxydomain.com:3000;

      }

我希望所有页面都来自上述 proxy_pass url,因为 https://subdomain.example.com/admin/sign

但此刻,我正试图访问登入页面(proxy_pass url 中的登录页面),它充当 https://subdomain.example.com/sign

任何意见都将受到赞赏!

答案1

这可行吗:

location /admin {
    proxy_buffering off;
    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;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass https://myproxydomain.com:3000/admin/;# 
}

如果这不起作用,那么您可以使用正则表达式捕获:

location ~ /admin(.*) {
    ...
    proxy_pass https://myproxydomain.com:3000/admin$1;
}

相关内容