Nginx – 为所有主机启用PHP

我目前正在testingnginx,并通过将每个虚拟主机的configuration放置在一个名为sites-enabled的文件夹中的自己的文件中来设置一些虚拟主机。

然后我问nginx加载所有这些configuration文件使用:

 include C:/nginx/sites-enabled/*.conf; 

这是我目前的configuration:

 http { server_names_hash_bucket_size 64; include mime.types; include C:/nginx/sites-enabled/*.conf; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; root C:/www-root; #charset koi8-r; #access_log logs/host.access.log main; location / { index index.html index.htm index.php; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } server{ server_name localhost; } } 

这是一个虚拟主机的configuration之一:

 server { server_name testsubdomain.testdomain.com root C:/www-root/testsubdomain.testdomain.com; } 

问题是,对于testsubdomain.testdomain.com,我不能让PHP脚本运行,除非我已经定义了一个与fastcgi参数的位置块。

我想要做的是能够启用PHP服务器上的所有托pipe网站(而不必添加一个PHP位置块与fastcgi参数)的可维护性。 这是如此,如果我需要改变PHP的任何fastcgi值,我可以改变它在1个位置。

这对于nginx是可​​能的吗? 如果是这样,怎么办?

我通常在我的conf.d文件夹内的Nginxconfiguration文件夹中的一个“全球”文件夹。 然后创build一个php.conf文件:

 location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } 

然后我只是将所有的configuration文件包含在虚拟主机中:

 include C:/nginx/conf.d/global/*.conf