nginx选择错误的默认站点

Sla*_*rix 3 nginx

首先,我知道我可以指定default_server强制默认站点,但我想了解为什么 nginx 不是简单地选择第一个定义server记录的站点。

httpnginx.conf 部分的末尾我有

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
Run Code Online (Sandbox Code Playgroud)

/etc/nginx/conf.d/*.conf 只是一些默认的代理配置和 ssl 配置

定义的站点是

000-default example.com zombo.com

默认站点指向本地目录和 index.html,另外两个指向代理服务器。

000-默认

server {
  listen   80;
  server_name  aaa-test;

  access_log  /var/log/nginx/localhost.access.log;

  location / {
    root   /var/www/nginx-default;
    index  index.html index.htm;
  }
}
Run Code Online (Sandbox Code Playgroud)

例子.com

server {

    server_name example.com *.example.com ;
    listen 80;

    location / {
        proxy_pass  http://10.245.0.19;
        proxy_redirect default;
    }

}
Run Code Online (Sandbox Code Playgroud)

zombo.com

server {

    server_name zombo.com *.zombo.com ;
    listen 80;

    location / {
        proxy_pass  http://10.245.0.36;
        proxy_redirect default;
    }

}
Run Code Online (Sandbox Code Playgroud)

但是如果我浏览 nginx 服务器的 IP,我会从 example.com 得到答案。我尝试重命名配置文件以按不同的顺序加载它们,并且始终将 example.com 作为默认值。即使我命名它的配置文件zzz.com

文档说没有 Host 标头的流量应该转到第一个虚拟主机,但我似乎无法做到这一点。

如果我删除 example.com,则流量会转到默认主机,而不是 zombo.com。

我真的被这里难住了......

编辑:评论要求的信息

# ls -lU /etc/nginx/sites-enabled
total 0
lrwxrwxrwx 1 root root 38 Oct  3 00:05 example.com -> /etc/nginx/sites-available/example.com
lrwxrwxrwx 1 root root 34 Oct  3 00:05 000-default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root 36 Oct  2 22:58 zombo.com -> /etc/nginx/sites-available/zombo.com
Run Code Online (Sandbox Code Playgroud)

Mic*_*ton 5

nginx正在查看第一个 defined server,但它不是您认为的那个。

如果您运行,ls -lU /etc/nginx/sites-enabled您将看到目录列表按照它出现在磁盘上的实际顺序,这是它们将被读取的顺序。这通常不是您期望的顺序。

当然,这也是您可以显式定义default_server.