加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

nginx选择错误的默认网站

发布时间:2020-12-13 21:10:28 所属栏目:Nginx 来源:网络整理
导读:参见英文答案 Nginx includes config files not in order?????????????????????????????????????3个 首先,我知道我可以指定default_server来强制默认站点,但我想了解为什么nginx不是简单地选择第一个定义的服务器为documented. 在nginx.conf的http部分结束时

参见英文答案 > 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的一个原因.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读