Ubuntu

導航到 www.domain.com 時,nginx 沒有顯示正確的頁面,當只是 domain.com

  • November 16, 2020

我正在嘗試在 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”相關的行,嘿,它確實有效。

希望這對將來的其他人有所幫助。

引用自:https://serverfault.com/questions/1042697