2015-03-03 52 views
5

我必須爲每個網站配置一個專用證書的多https網站。它的工作正常。多「服務器」塊的相同「位置」規則

server { 
     listen 443; 
     server_name client1.localhost.eu; 

     ssl on; 
     ssl_certificate ...; 
     ssl_certificate_key ...; 

     root /var/www/client1; 

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

server { 
     listen 443; 
     server_name client2.localhost.eu; 

     ssl on; 
     ssl_certificate ...; 
     ssl_certificate_key ...; 

     root /var/www/client2; 

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

現在,我想分解「位置」塊,因爲它總是相同的。可能嗎 ? (我也試圖只在服務器塊上,但不可能把變量放在ssl屬性中)

非常感謝您的幫助。

埃裏克

回答

7

使用包括這樣的分解指令:

include

創建像 /etc/nginx/conf.d/location_php.cnf nginx的config文件夾文件(沒有的.conf以避免nginx自動加載)

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

然後將它包含到服務器塊中:

server { 
     listen 443; 
     server_name client1.localhost.eu; 

     ssl on; 
     ssl_certificate ...; 
     ssl_certificate_key ...; 

     root /var/www/client1; 
     include /etc/nginx/conf.d/location_php.cnf; 
     # OR use relative path to nginx config root: 
     # include conf.d/location_php.cnf; 
} 
+1

喔,很簡單!感謝和sry爲這個noob問題:) – elhostis 2015-03-03 13:44:55

相關問題