我正在尝试在 ubuntu 上部署 nginx / gunicorn / flask,当我导航到“domain.com”时一切似乎都正常工作,但是当我转到“www.domain.com”时,我得到了 nginx 的默认启动画面。
nginx 设置如下。
server {
server_name thecomputermade.me www.thecomputermade.me;
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/imageRate/imageRate.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/thecomputermade.me/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/thecomputermade.me/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = thecomputermade.me) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name thecomputermade.me;
return 404; # managed by Certbot
}
当我运行时,systemctl status nginx
我得到了下面的内容。
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2020-11-16 08:54:05 UTC; 999ms ago
Docs: man:nginx(8)
Process: 1430 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 1442 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 1443 (nginx)
Tasks: 2 (limit: 560)
Memory: 2.9M
CGroup: /system.slice/nginx.service
├─1443 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─1444 nginx: worker process
Nov 16 08:54:05 ip-172-26-6-186 systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 16 08:54:05 ip-172-26-6-186 nginx[1430]: nginx: [warn] conflicting server name "www.thecomputermade.me" on 0.0.0.0:443, ignored
Nov 16 08:54:05 ip-172-26-6-186 nginx[1442]: nginx: [warn] conflicting server name "www.thecomputermade.me" on 0.0.0.0:443, ignored
Nov 16 08:54:05 ip-172-26-6-186 systemd[1]: Started A high performance web server and a reverse proxy server.
请注意显示服务器名称冲突的那一行...
我已经在 nginx 配置中尝试过 thecomputermade.me:
- “thecomputermade.me” 按预期工作,但“www.thecomputermade.me”再次导航到 nginx 的默认启动画面。
当我在配置中仅添加“www.thecomputermade.me”时:
- 两个地址都浏览默认启动画面,并且我收到了冲突的服务器名称警告。
有人知道我需要做什么吗?
答案1
好的,我已经解决了。
我第一次运行sudo grep -r www.thecomputermade.me /etc/nginx
这个程序时显示了对该域的多个引用。
正如错误所言,这意味着存在冲突的服务器名称。
为什么会发生这种情况?
事实证明 certbot 在“默认”配置文件中添加了一些数据/etc/nginix/sites-available
。
为了修复这个问题,我注释掉了默认配置文件中所有与“www.thecomputermade.me”相关的行,然后,瞧,它起作用了。
希望这能在未来帮助到其他人。