2014-01-29 63 views
5

使用Nginx,我爲包含四個單獨站點的服務器創建了一個多域設置。當我啓動Nginx時,我收到一條錯誤消息,這些網站似乎混在一起,因爲輸入一個網址會導致其他網站之一。一臺服務器上的多個域指向錯誤的站點

顯示的錯誤信息 -

Restarting nginx: nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored 
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored 
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored 
nginx. 

我已經成立了類似的方式全部四個領域在各自的文件在/站點可用 -

server { 
     listen 80; 

     root /var/www/example.com/public_html; 
     index index.php index.html index.htm; 

     server_name example.com www.example.com; 

     location/{ 
       try_files $uri $uri/ /index.html; 
     } 

     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
     location ~ \.php$ { 
       try_files $uri =404; 
       fastcgi_pass unix:/var/run/php5-fpm.sock; 
       fastcgi_index index.php; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
       include fastcgi_params; 

     } 

} 

我檢查和/ sites-enabled中沒有默認文件。猜測Nginx主配置中可能存在錯誤的設置,但不確定要查找什麼。

+0

也許你已經在主配置文件中定義的'server'('nginx.conf')? –

+0

不,只需http和事件選項。特別是我應該尋找什麼? –

+0

我問,因爲默認的'nginx.conf'有一堆例子'服務器'塊,也許你忘了刪除它們。什麼是你的主要配置文件?你可以發佈到pastebin或類似的東西嗎? –

回答

2

如果有任何臨時文件(例如~default),請查看/etc/nginx/sites-enabled/目錄。刪除它並解決問題。

信用:@OmarIthawi nginx error "conflicting server name" ignored

+0

謝謝,但我已經在早期的設置中刪除了這個。 –

9

nginx.conf從你在你的include指令具有路徑加載其外部服務器上的文件。

如果你有一個文件在include /etc/nginx/conf.d/*.conf;和它的符號鏈接到include /etc/nginx/sites-enabled它將加載文件兩次,這將導致該錯誤。

+0

謝謝@JClarke。這解決了我的問題。我剛剛評論過「include /etc/nginx/conf.d/*.conf;」在我的nginx.conf文件中出現,並且錯誤信息消失了! –

1

在我的情況下,沒有網站啓用雙也包括....

溶液避免超過一個參考(如果考慮所有的conf.d文件作爲一個整體)「聽80」和「server_name」引用...

在我的情況下,default.conf和kibana.conf都包括對這個傢伙的引用......我評論了默認和解決問題的人!

我的2美分....

3

我有同樣的問題,我的Ubuntu/nginx的/ gunicorn/Django的我的本地機器上的1.9網站。我在/ etc/nginx/sites-enabled中有兩個nginx文件。刪除允許剩餘網站工作的任何一個。把兩個文件都放到兩個站點中的一個。我不確定它是如何選擇的。

所以看着幾個堆棧溢出問題都沒有找到解決辦法後,我就在這裏:http://nginx.org/en/docs/http/request_processing.html

它結束了,你可以有多個服務器在一個啓用了站點文件,所以我改成這樣:

server { 
    listen 80; 
    server_name joelgoldstick.com.local; 
    error_log /var/log/nginx/joelgoldstick.com.error.log debug; 
    location/{ 
     proxy_pass http://127.0.0.1:8002; 
    } 
    location /static/ { 
     autoindex on; 
     alias /home/jcg/code/python/venvs/jg18/blog/collect_static/; 
    } 
} 

server { 
    listen 80; 
    server_name cc-baseballstats.info.local; 
    error_log /var/log/nginx/baseballstats.info.error.log debug; 
    location/{ 
     proxy_pass http://127.0.0.1:8001; 
    } 
    location /static/ { 
     autoindex on; 
     alias /home/jcg/code/python/venvs/baseball/baseball_stats/collect_static/; 
    } 
} 

我現在可以同時訪問我的網站的本地

相關問題