我必须为每个网站配置一个具有专用证书的多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属性中放置变量)
非常感谢你的帮助。
埃里克
答案 0 :(得分:10)
使用include指令进行此类分解:
在nginx配置文件夹中创建文件,如 /etc/nginx/conf.d/location_php.cnf(不是.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;
}