centos 7 上的 nginx 正在使用 www.domain.tld 而不是 domain.tld 服务页面(所有请求都是端口 80 上的 http)

nginx on centos 7 is servicing pages using www.domain.tld but not domain.tld (all request are http on port 80)

我遇到了以下问题:
我的 centos 7 vps 配置了 nginx 和两个服务器块(虚拟主机)
对于这两个域,我可以使用 www.domain.tld 但不能使用 domain.tld 访问网页。
访问 domain.tld
时未生成错误或访问日志 已检查 Dns 记录并指向具有空 A 记录的服务器 IP 地址(当服务器配置为 ubuntu 18.04、iRedMail、nextcloud 和两个网站时,相同的 dns 记录正常工作)。

浏览器中的错误消息是:"This site can’t be reached. domain.tld refused to connect."

下面是配置文件(nginx和一个域),我已经包含了参考路径:

nginx.conf

#cat /etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

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

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    include /etc/nginx/sites-enabled/*.conf;
    server_names_hash_bucket_size 64;


  server {
    listen 80 default_server;
    server_name "";
    return 444;
  }
}

* default_server用于防止访问http:\serverIP时访问nginx欢迎页面。将此配置返回到 nginx 默认值不会影响行为。

域配置

# cat /etc/nginx/sites-enabled/domain.tld.conf 

server {
   listen   80;
   server_name  domain.tld www.domain.tld;

   location / {
        root  /var/www/domain.tld;
        index  index.html index.htm;
   }

   error_page 404 /404.html;
       location = /40x.html {
   }

   error_page 500 502 503 504 /50x.html;
       location = /50x.html {
   }
# Setting log locations
   access_log /var/log/nginx/domain.tld-access.log;
   error_log /var/log/nginx/domain.tld-error.log debug;
}

不得不提的是,这个VPS的目的是学习基本的Linux sysadmin,因此没有真正的数据或限制,也是我第一次接触centos。

感谢您的时间和精力。

L.E。 将“127.0.0.1 www.domain.tld domain.tld”添加到 /etc/hosts 并不能解决问题。这两个域都是带有 DNS 服务器的真实域,并且所有记录都被复制。此外,使用到域的跟踪路由 VPS IP 已达到。

Nginx 配置验证成功

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

经过进一步调查,我注意到在访问 domain.tld 时,访问或错误日志(错误设置为调试)中没有出现任何请求,但 www.domain.tld 会直接将我发送到 DNS,但使用一些在线挖掘版本检查 DNS 一切似乎都正常,domain.tld 和 www.domain.tld 都指向正确的 VPS ip

在花了将近两天的时间试图找出导致此问题的原因后,我在另一台 PC 上远程访问了该网站,但令我惊讶的是,一切正常。 现在我确定我已经多次清除了我的 DNS 缓存,但显然问题是由插件 httpsEverywhere 引起的。

谢谢,我保证下次会更加努力:D