lnmp不同虚拟机主机配置不同php-fpm的pool、慢日志

当一台lnmp服务器上有多个虚拟主机,并且不同虚拟主机的业务类型差别很大时可能需要有不同的php-fpm配置,以及不同的慢日志已定位问题。

php7默认使用了辅助配置文件

include=/usr/local/php-7.2/etc/php-fpm.d/*.conf

进入php配置文件目录

cd /usr/local/php/etc/php-fpm.d

可以根据虚拟主机的域名创建一个配置文件

cp www.conf test.conf
vim /usr/local/php/etc/php-fpm.d/test.conf
# 指定独立的spool
[test]
user = nobody
group = ftpwork
# 指定独立的套接字文件
listen = /dev/shm/test_php.sock
listen.owner = nobody
listen.group = nobody
listen.mode = 0666
pm = static 
pm.max_children = 50
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.process_idle_timeout = 60s;
pm.max_requests = 500
# 根据spool名称设置慢日志
slowlog = /usr/local/php/var/log/$pool.log.slow
request_slowlog_timeout = 5

nginx虚拟主机指定连接php的套接字文件

server {
    listen 80;
    server_name    test.abc.com;
    access_log     /home/weblog/test_access.log main;
    error_log      /home/weblogerr/test_error.log;
    set        $root    /home/httpd/test;
    location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
    {
        root $root;
        access_log off;
    }
    location / {
        root    $root;
        index    index.php;
        if ( -f $request_filename) {
            break;
        }
        if ( !-e $request_filename) {
            rewrite ^(.*)$ /index.php/$1 last;
            break;
        }
    }
    location ~ .+\.php($|/) {
        # 配置专用的spool 
        fastcgi_pass unix:/dev/shmp/test_php.sock;
        fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param    SCRIPT_FILENAME    $root$fastcgi_script_name;
        include        fastcgi_params;

    }
}

 

 

 

 

 

发表评论