Nginx 服务器匹配太多 URL

发布于 2024-08-21 20:19:16 字数 898 浏览 12 评论 0原文

我有一个域 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>
}

点击 :8745 将转到该虚拟主机,它按预期工作。然而,我有另一个像这样的虚拟主机:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

维持三分热 2024-08-28 20:19:16

我也在服务器故障上问过这个问题,但是我自己找到了原因。以下摘录摘自此问题

事实证明这不是 nginx
问题。我可能应该注意到这一点
<我的服务器 IP>:8746 运行 Wordpress
安装; WordPress 有一个选项
设置(在 wp_options 表中,行
我的 option_id 为 2 并且
siteurloption_name) 到 .com,我将其更改为 .com:8746 并且工作正常。

I asked this on Server Fault also, however I found out the cause on my own. The below excerpt is pulled from this question.

It turns out this isn't an nginx
issue. I probably should've noted that
<my server IP>:8746 runs a Wordpress
installation; Wordpress has an option
set (in the wp_options table, the row
has option_id of 2 for me and
option_name of siteurl) to <some
domain>.com
, I changed that to <some
domain>.com:8746
and it worked fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文