nginx选择错误的默认网站

前端之家收集整理的这篇文章主要介绍了nginx选择错误的默认网站前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

参见英文答案 > Nginx includes config files not in order?                                    3个
首先,我知道我可以指定default_server来强制默认站点,但我想了解为什么Nginx不是简单地选择第一个定义的服务器为documented.

Nginx.conf的http部分结束时我有

include /etc/Nginx/conf.d/*.conf;
include /etc/Nginx/sites-enabled/*;

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

定义的网站是

000默认
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;
  }
}

example.com

server {

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

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

}

zombo.com

server {

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

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

}

但如果我浏览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
最佳答案
Nginx正在查看第一个定义的服务器,但它不是您认为的那个.

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

当然,这是您可以明确定义default_server的一个原因.

原文链接:https://www.f2er.com/nginx/435151.html

猜你在找的Nginx相关文章