2014-09-05 23 views
0

多個站點的正確部署我與服務器一個業餘,我在我的本地Ubuntu的機器上設置Nginx的。我有多個站點在本地工作,作爲轉移到實時服務器的練習。我不確定這是否是針對相關網站的最佳設置。他們是WordPress的網站。使用Nginx的

每個站點文件夾是在var/www

/var/www/site1 
/var/www/site2 

我SYM鏈接的默認文件中/etc/nginx/sites-available/default/etc/nginx/sites-enabled/default。保持原樣。特別注意傾聽部分;

server { 
     listen 80 default_server; 
     listen [::]:80 default_server ipv6only=on; 

使用此文件爲基礎,我做了兩個網站一樣,在創建網站可爲每個單獨的文件和SYM它們鏈接到網站啓用 - 。這裏是site1s的設置;

server { 
     listen 80; 
     listen [::]:80; 

     root /var/www/site1; 
     index index.php index.html index.htm; 

     server_name local.site1.com; #for testing, edited in hosts 

     location/{ 
       try_files $uri $uri/ /index.php?q=$uri&$args; 
     } 

     error_page 404 /404.html; 
     error_page 500 502 503 504 /50x.html; 
     location = /50x.html { 
       root /usr/share/nginx/html; 
     } 

     location ~ \.php$ { 
       try_files $uri =404; 
       fastcgi_split_path_info ^(.+\.php)(/.+)$; 
       fastcgi_pass unix:/var/run/php5-fpm.sock; 
       fastcgi_index index.php; 
       include fastcgi_params; 
     } 
} 

我的問題很簡單;這是設置Nginx服務器的有效方式嗎? This線程將我的設置列爲選項,但其效率沒有任何提高。我在默認站點中啓用了'default_server',我的實際站點只是監聽端口80;我真的不知道在端口上..

我覺得在這一點上每個站點都有一個'專用'的數據庫服務器(塊),但也許這是一個完全不同的水壺..

+0

你擔心什麼樣的效率? – Brad 2014-09-05 16:47:00

+0

我聽說過的Nginx與響應擴展需求(與Apache的),但我不知道是否有任何特殊的配置,以使這個或者如果它只是默認 – myol 2014-09-08 10:24:37

+1

「作品」無論是Nginx的還是Apache可以自動擴展任何東西..因爲你通常會談論多個服務器和其他的東西。 Nginx具有比Apache更高效的線程模型,這可能是您聽說過的。而且,由於這與Nginx的設計而不是配置有關,它只是起作用。 – Brad 2014-09-08 13:27:29

回答

3

您的配置沒問題,只需使用includes,就可以從1個文件中更改所有站點的全局參數。

site1s.conf:

server { 
    root /var/www/site1; 
    server_name local.site1.com; #for testing, edited in hosts 

    include /etc/nginx/conf.d/global.cnf; 
} 

site2s.conf ... siteNs.conf從site1s.conf克隆(你改變只有2線,hostsnames)

/etc/nginx/conf.d /global.cnf(或者你喜歡的任何名字,但是最好不要使用.conf擴展名,以避免nginx自動加載 - 我不知道你所有的配置):

listen 80; 
listen [::]:80; 

index index.php index.html index.htm; 

location/{ 
     try_files $uri $uri/ /index.php?q=$uri&$args; 
} 

error_page 404 /404.html; 
error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
     root /usr/share/nginx/html; 
} 

location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     include fastcgi_params; 
}