问题描述
在购买了域名 rendshub.today 后,做了基本的nginx配置,但是在输入一些列网址后页面解析会出现请求失败,DNS解析问题,比如希望输入以下网址时,最终转成 https://www.trendshub.today,但最终只有www.trendshub.com和http://www.trendshub.today自动转成功了
trendshub.today
www.trendshub.today
http://trendshub.todayhttp://www.trendshub.today
http://trendshub.today
https://trendshub.today
我的 nginx 配置如下:
server {
listen 80;
server_name trendshub.today;
# 重定向所有 http 请求到 https://www.trendshub.today
return 301 https://www.trendshub.today$request_uri;
}
server {
listen 80;
server_name www.trendshub.today;
# 重定向所有 http 请求到 https
return 301 https://www.trendshub.today$request_uri;
}
server {
listen 443 ssl http2;
server_name trendshub.today;
ssl_certificate /etc/nginx/SSL/trendshub.today.pem;
ssl_certificate_key /etc/nginx/SSL/trendshub.today.key;
# 重定向所有 https 请求到 https://www.trendshub.today
return 301 https://www.trendshub.today$request_uri;
}
server {
listen 443 ssl http2;
server_name www.trendshub.today;
ssl_certificate /etc/nginx/SSL/trendshub.today.pem;
ssl_certificate_key /etc/nginx/SSL/trendshub.today.key;
# 将根路径的请求代理到端口 3000
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
解决思路及方案
1. 首先排查了下nginx的配置问题,且对比了下 gpt 的答案,看起来没有问题
2. chrome 浏览器报错信息是
无法访问此网站检查 trendshub.today 中是否有拼写错误。 如果拼写无误,请尝试运行 Windows 网络诊断。 DNS_PROBE_FINISHED_NXDOMAIN
由此将问题聚焦到了dns解析的问题上
利用如下指令,查看域名是否正确指向服务器ip
nslookup trendshub.today
nslookup www.trendshub.today
发现 trendshub.today 的dns记录没有添加顶级域名,所以需要在阿里云域名解析添加@记录即可
完结撒花~~~