2012-06-26 15 views

回答

-1

您應該使用bash/sh聽。 Unix方式。

+0

你能否詳細說明一下?這是一個非常神祕的答案。 – Gnarfoz

+0

您應該使用腳本來部署您的站點,並運行命令,如'make production'或'make testing',它將自動生成nginx配置。 – VBart

+0

這個問題沒有包含對部署的任何引用,所以我假設它圍繞使用nginx並行運行生產版本和測試版本。 – Gnarfoz

2

你可以把所有在一個單獨的文件共享的部分(比如,common.conf),幷包括兩個簡約server塊,像這樣:

http { 
    [...] 
    server { 
     listen 80; 
     server_name production.local; 

     root /some/path/production; 
     include common.conf; 
    } 

    server { 
     listen 81; 
     server_name testing.local; 

     root /some/path/testing; 
     include common.conf; 
    } 
} 

編輯 事實上,你甚至不需要listen指令。以root用戶身份運行時默認爲listen 80,否則爲listen 8000。只要你有一個DNS條目,或主機文件條目,你會很好。

+0

你說他們默認使用80端口是正確的。即使你寫了,它會給你一個錯誤,說8080被另一個端口使用。所以基本上url將是www.example.com:80,但是你不需要寫80,因爲它默認是在那裏。但爲了服務www.example2.com:8084,您需要提及端口號以獲取地址。如何在不明確添加端口地址的情況下工作? –

+0

如果在配置的任何位置沒有'listen 8080;',它不會抱怨端口8080正在使用中。 [如果你沒有以root身份運行nginx,它可能會抱怨8000端口(http://nginx.org/en/docs/http/ngx_http_core_module.html#listen)。無論如何,如果你想使用8084端口,你將不得不在你的配置中使用'listen 8084;'(或類似的)。 – Gnarfoz

相關問題