【发布时间】:2020-07-07 01:23:01
【问题描述】:
我遇到以下问题:
我的 centos 7 vps 配置了 nginx 和两个 server-blocks (vhosts)
对于这两个域,我可以使用 www.domain.tld 访问网页,但不能使用 domain.tld。
访问 domain.tld 时不会生成错误或访问日志
dns 记录被检查并指向具有空 A 记录的服务器 IP 地址(当服务器配置 ubuntu 18.04、iRedMail、nextcloud 和两个网站时,相同的 dns 记录正常工作)。
浏览器中的错误消息是:“无法访问此站点。domain.tld 拒绝连接。”
以下是配置文件(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 Witch 会直接将我发送到 DNS,但使用一些 dig 在线版本检查 DNS 似乎一切正常,domain.tld 和 www.domain.tld 都指向正确的 VPS ip
【问题讨论】:
标签: nginx nginx-config