2010-08-16 70 views
0

我的nginx.conf文件越來越大,數十個虛擬主機一遍又一遍地重複相同的行。我想知道是否有無論如何宣佈在全球範圍以下,而不必重複它們對每個項目:Nginx更好的VHOST管理?

# Route all requests for non-existent files to index.php 
if (!-e $request_filename) { 
rewrite ^(.*)$ /index.php/$1 last; 
} 

location ~ \.php($|/) { 
include fastcgi_params; 
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
fastcgi_pass 127.0.0.1:9000; 
} 
+0

這個問題更可能更適合於serverfault ... – ircmaxell 2010-08-16 19:49:32

回答

3

爲您的虛擬主機(即vhost.conf)共同設置創建一個文件。無論你想使用這個通用設置,只需包含該vhost.conf文件即可。

server { 
    include vhost.conf 

    location /test { 
     # Custom setup for /test 
    } 
} 

路徑相對於你的nginx.conf文件,如果你的nginx.conf路徑之外指定vhost.conf使用絕對路徑。 http://wiki.nginx.org/NginxHttpMainModule#include

+0

你保存了一天 – Xeoncross 2010-08-16 20:36:23