为了避免因多站点使用同一个pool时因一个站点故障导致pool出问题,进而影响使用同一个pool的其他站点的正常运行,要对每个站点配置一个单独的pool。
为php-fpm增加pool
编辑php-fpm配置文件:
vim /usr/local/php-fpm/etc/php-fpm.conf
……
[aming.com]
listen = /tmp/aming.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
语法检测:
/usr/local/php-fpm/sbin/php-fpm -t
重新加载配置文件:
/etc/init.d/php-fpm reload
/usr/local/nginx/sbin/nginx -s reload
查看进程:
ps aux |grep php-fpm
为站点配置pool
vim /usr/local/nginx/conf/vhost/aaa.conf
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/aming.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
}
说明: 把fastcgi_pass地址改为和php-fpm.conf中一样的地址就可以。
mkdir /data/wwwroot/aaa.com
添加php-fpm.conf子配置文件
为了便于管理,可以将php-fpm中的每个pool单独进行管理。进行如下操作,添加php-fpm子配置文件:
vim /usr/local/php-fpm/etc/php-fpm.conf
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
include = etc/php-fpm.d/*.conf
说明: 在全局变量版块添加参数“include = etc/php-fpm.d/*.conf”。然后可以清除php-fpm配置文件中其他参数,再到php-fpm.d目录下进行单独设置。
cd /usr/local/php-fpm/etc/
创建指定目录:
mkdir php-fpm.d
cd php-fpm.d/
创建php-fpm子配置文件:
vim www.conf
[www]
listen = /tmp/php-fcgi.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
vim aming.conf
[aming.com]
listen = /tmp/aming.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
检查语法错误、重新加载:
/usr/local/php-fpm/sbin/php-fpm -t
/etc/init.d/php-fpm reload
配置完成后使用ps查看php-fpm进程信息。