我正在尝试在 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 配置中尝试了 computermade.me:
- “thecomputermade.me”按预期工作,但“www.thecomputermade.me”再次导航到 nginx 的默认启动屏幕。
当我在配置中仅添加“www.thecomputermade.me”时:
- 两个地址都导航默认启动画面,我收到冲突的服务器名称警告。
有谁知道我需要做什么?
好的,所以我已经解决了。
首先,我运行
sudo grep -r www.thecomputermade.me /etc/nginx
它显示了对该域的多个引用。这意味着,正如错误所说。服务器名称存在冲突。
为什么会这样?
原来 certbot 将一些数据添加到
/etc/nginix/sites-available
.为了解决这个问题,我在默认配置文件中注释掉了所有与“www.thecomputermade.me”相关的行,嘿,它确实有效。
希望这对将来的其他人有所帮助。