如何在Nginx中保留代理重定向最终url中的子域和基本路径
基本上,我在正确设置代理重定向时遇到了问题。基本上,我希望执行代理重定向,如下所示:如何在Nginx中保留代理重定向最终url中的子域和基本路径,nginx,redirect,reverse-proxy,Nginx,Redirect,Reverse Proxy,基本上,我在正确设置代理重定向时遇到了问题。基本上,我希望执行代理重定向,如下所示: http://subdomain.domain.com/test1/test2/test3 -> http://subdomain.another.com/test1/test2/test3 proxy_redirect ~^(http://[^\.]+)\.domain\.com/(.+)$ http://$1.another.com/$2; 在这里,子域和url路径(即/test1/test2/
http://subdomain.domain.com/test1/test2/test3 -> http://subdomain.another.com/test1/test2/test3
proxy_redirect ~^(http://[^\.]+)\.domain\.com/(.+)$ http://$1.another.com/$2;
在这里,子域和url路径(即/test1/test2/test3)不断变化,所以在这里,我必须从重定向url中获取它们并将其传递到最终url
我试着这样做:
http://subdomain.domain.com/test1/test2/test3 -> http://subdomain.another.com/test1/test2/test3
proxy_redirect ~^(http://[^\.]+)\.domain\.com/(.+)$ http://$1.another.com/$2;
请提供任何解决方案。此重写使用正则表达式,将在更改域时保留路径:
server {
listen 80;
server_name subdomain.domain.com;
location / {
rewrite ^/(.*)$ subdomain.another.com/$1;
}
}
阅读nginx代理模块文档。你完全在做什么wrong@AlexeyTen我想是regex。请提出一些建议。我已经阅读了文档,但在regex中没有什么混淆。您是否意识到此指令仅适用于
位置
标题?