我们应该为每个虚拟主机或在全局配置中添加 php-fpm 吗?
Should we add php-fpm for each Virtual Host or in Global Configuration?
这是我的虚拟主机配置。我不确定,但这是定义事物的理想方式吗?
对于每个域/子域,我添加了一个 location ~/.php 指令。我应该将它添加到全局 nginx.conf 本身而不是为我添加的每个域单独指定吗?
示例配置:-
server {
listen 80;
server_name example.com;
location / {
root /var/www/example.com;
index index.php;
}
location ~ \.php$ {
root /var/www/example.com/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_read_timeout 30000;
#fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
server {
listen 80;
server_name www.example.net;
location / {
root /var/www/example.net/;
index index.php;
}
location ~ \.php$ {
root /var/www/example.net/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_read_timeout 30000;
# fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
您不能将 location
放在 server
块之外。您能做的最好的事情就是将重复的部分放入文件中,然后 include
该文件。
此外,通常你不应该在每个 location
中声明 root
指令,在 server
.
中声明一次
而且,顺便说一句,index
指令可以在 server
块之外,在这种情况下,它会影响所有没有自己的 index
指令的 server
块.
这里的配置与您的保存完全相同,但重复次数较少。
index index.php;
server {
listen 80;
server_name example.com;
root /var/www/example.com;
include location-php;
}
server {
listen 80;
server_name example.net;
root /var/www/example.net;
include location-php;
}
和location-php
文件:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
这是我的虚拟主机配置。我不确定,但这是定义事物的理想方式吗?
对于每个域/子域,我添加了一个 location ~/.php 指令。我应该将它添加到全局 nginx.conf 本身而不是为我添加的每个域单独指定吗?
示例配置:-
server {
listen 80;
server_name example.com;
location / {
root /var/www/example.com;
index index.php;
}
location ~ \.php$ {
root /var/www/example.com/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_read_timeout 30000;
#fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
server {
listen 80;
server_name www.example.net;
location / {
root /var/www/example.net/;
index index.php;
}
location ~ \.php$ {
root /var/www/example.net/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_read_timeout 30000;
# fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
您不能将 location
放在 server
块之外。您能做的最好的事情就是将重复的部分放入文件中,然后 include
该文件。
此外,通常你不应该在每个 location
中声明 root
指令,在 server
.
而且,顺便说一句,index
指令可以在 server
块之外,在这种情况下,它会影响所有没有自己的 index
指令的 server
块.
这里的配置与您的保存完全相同,但重复次数较少。
index index.php;
server {
listen 80;
server_name example.com;
root /var/www/example.com;
include location-php;
}
server {
listen 80;
server_name example.net;
root /var/www/example.net;
include location-php;
}
和location-php
文件:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}