【发布时间】:2012-10-19 05:48:24
【问题描述】:
目前,我需要放
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
}
在我需要运行 PHP 文件的每个站点中。
有没有办法把它放在一个“master”中,这样所有网站都不会有相同指令的重复副本?
【问题讨论】:
目前,我需要放
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
}
在我需要运行 PHP 文件的每个站点中。
有没有办法把它放在一个“master”中,这样所有网站都不会有相同指令的重复副本?
【问题讨论】:
是的,就像这样:
include /etc/nginx/master.conf;
更多详情见http://nginx.org/en/docs/ngx_core_module.html#include
换句话说,你有:
server {
servername a;
location ~ \.php$ { fastcgi_pass 127.0.0.1:9000;}
#rest of server a config
}
server {
servername b;
location ~ \.php$ { fastcgi_pass 127.0.0.1:9000;}
#rest of server b config
}
你现在有:
server {
servername a;
include /etc/nginx/php-master.conf;
#rest of server a config
}
server{
servername b;
include /etc/nginx/php-master.conf;
#rest of server b config
}
和一个单独的文件 /etc/ningx/php-master.conf 作为内容
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
}
它实际上并没有大大缩短 serverblock 中的代码(因为包含的位只是 1 行)。但它仍然具有优势,您现在可以在 1 个位置更改 php 设置(例如,您将 fastcgi 处理程序移动到不同的端口或 ip)
【讨论】:
location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; } PHP 文件也无法在单个站点上运行,除非我将相同的代码放在自己的 server { } 块中跨度>