我目前正在测试 nginx 并设置了一些虚拟主机,方法是将每个虚拟主机的配置放在一个名为sites-enabled
.
然后我要求 nginx 使用以下命令加载所有这些配置文件:
include C:/nginx/sites-enabled/*.conf;
这是我当前的配置:
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;
}
}
这是虚拟主机的配置之一:
server {
server_name testsubdomain.testdomain.com
root C:/www-root/testsubdomain.testdomain.com;
}
问题是对于 testsubdomain.testdomain.com,我无法让 php 脚本运行,除非我为它定义了一个带有 fastcgi 参数的位置块。
我想做的是能够为此服务器上的所有托管站点启用 PHP(无需添加带有 fastcgi 参数的 PHP 位置块)以实现可维护性。这样一来,如果我需要更改 PHP 的任何 fastcgi 值,我只需在 1 个位置更改它。
这对 nginx 来说是可能的吗?如果是这样,如何做到这一点?
我通常在 Nginx 配置文件夹内的 conf.d 文件夹中创建一个“全局”文件夹。然后创建一个 php.conf 文件:
然后我只包含虚拟主机中的所有配置文件: