Nginx 在 0.0.0.0:80 上衝突的伺服器名稱“”,被忽略

Nginx 在 0.0.0.0:80 上衝突的伺服器名稱“”,被忽略

我無法弄清楚如何解決運行時的以下警告nginx -t

2022/12/29 05:10:23 [warn] 24920#24920: conflicting server name "" on 0.0.0.0:80, ignored
2022/12/29 05:10:23 [warn] 24920#24920: conflicting server name "" on [::]:80, ignored

我的伺服器上運行著兩個網站。

  1. 主頁設定檔
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/home;

    index index.html

    server_name int.mycompany.lan;

    location / {
       # First attempt to serve request as file, then
       # as directory, then fall back to displaying a 404.
       try_files $uri $uri/ =404;
    }
 }
  1. 錯誤設定檔
server {
    listen 80;
    listen [::]:80;

    root /var/www/bug;

    index index.html

    server_name bug.int.mycompany.lan;

    location / {
       # First attempt to serve request as file, then
       # as directory, then fall back to displaying a 404.
       try_files $uri $uri/ =404;
    }
 }

前往網站bug.int.mycompany.lan總是向我展示int.mycompany.lan網站代替。

如果我從 /etc/nginx/sites-enabled 中刪除這些文件之一的符號鏈接,或者如果我將其中一個站點上的端口更改為 8081 之類的端口,那麼我將不再收到上述錯誤。

答案1

愚蠢的錯誤。我刪除了該行的分號index。我花了幾個小時才發現。

相關內容