Nginx 服务器匹配太多 URL
我有一个域 example.com
和一个 some-example.com
的“替代”域。我正在尝试使用 nginx 中的简单服务器声明将流量从 some-example.com
定向到 example.com
,如下所示:
server {
listen 80;
server_name some-example.com;
rewrite ^/(.*) http://example.com/$1 permanent;
}
我不能 100% 确定这是否有效是正确的规则,但我的服务器上有另一个虚拟主机,这不是问题所在,但有必要了解我遇到的问题。
server {
listen 8745;
server_name localhost;
<other stuff goes here>
}
点击
将转到该虚拟主机,它按预期工作。然而,我有另一个像这样的虚拟主机:
server {
listen 8746;
server_name localhost;
<other stuff goes here>
}
但是我对<我的服务器IP>:8746
的所有请求都命中了example.com
。我……很困惑,我不太了解 nginx,所以任何关于为什么会发生这种情况的帮助将不胜感激。我一开始就提到了这条规则,因为我认为它与此有关。如果需要更多信息,我可以提供。
(另外,这对于服务器故障会更好吗?)
I've got a domain example.com
and an "alternative" of some-example.com
. I'm trying to direct traffic from some-example.com
to example.com
using a simple server declaration in nginx as follows:
server {
listen 80;
server_name some-example.com;
rewrite ^/(.*) http://example.com/$1 permanent;
}
I'm not 100% sure if this is the right rule, but I've got another vhost on the server, this isn't where the problem is, but it's necessary to understand the issue I'm having.
server {
listen 8745;
server_name localhost;
<other stuff goes here>
}
Hitting <my server IP>:8745
will go to that vhost, that works as intended. However I've got another vhost like this:
server {
listen 8746;
server_name localhost;
<other stuff goes here>
}
But all of my requests to <my server IP>:8746
hit example.com
. I'm... baffled, I don't really grok nginx, so any help would be appreciated as to why this is happening. I mentioned that rule in the beginning because I'm thinking it has something to do with this. If additional information is needed I can supply it.
(Also, would this be better for Server Fault?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也在服务器故障上问过这个问题,但是我自己找到了原因。以下摘录摘自此问题。
I asked this on Server Fault also, however I found out the cause on my own. The below excerpt is pulled from this question.