nginx-将特定路径重定向到另一个域 [英] nginx - redirect a certain path to another domain
问题描述
作为一个警告,我非常不熟悉nginx,并且在使用的regex系统上也找不到任何实际的引用.所以现在对我来说这是一个黑匣子.
I am very unfamiliar with nginx, as a forewarning, and also can't find any actual references on the regex system they use. So right now it's a black box to me.
我要做的就是将试图访问www.mydomain.com/mydirectory/X的用户重定向到www.myotherdomain.com/X.
All I want to do is redirect a user trying to go to www.mydomain.com/mydirectory/X to www.myotherdomain.com/X .
似乎我应该使用rewrite命令,但是正则表达式的语法使我难以理解.
Seems like I should be using the rewrite command but the syntax of the regex is eluding me.
提前谢谢.
推荐答案
我提出了一个可行的解决方案.在发布这个问题之前我已经知道了,但是没有意识到我需要重启nginx.将以下内容放入您的服务器块中.
I made a solution that works. I had it before posting this question but didn't realize I needed to restart nginx. Put the following inside your server block.
rewrite ^(/mydirectory/)(.*)$ http://www.myotherdomain.com/$2 permanent;
这篇关于nginx-将特定路径重定向到另一个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!