Nginx+php_fpm参数优化

部署的nginx+php7.0_fpm最近在客户使用的时候,偶尔会出现502错误,后台查看日志fpm挂掉了,重启网站就恢复了,初步估计是配置问题,然后对nginx和php的配置进行了一些列优化。

php.ini配置调优
max_execution_time = 5 //php最大执行时间,看个人情况设置
memory_limit = 256M    //php能使用的最大内存
default_socket_timeout = 5

file_uploads = On 
upload_tmp_dir = /tmp/php
upload_max_filesize = 50M
post_max_size = 50M
max_file_uploads = 20

PHP-FPM配置调优

# php-fpm.conf
[my_app]

;估算pm.max_children = (MAX_MEMORY - 500MB) / 20MB
pm.max_children = 100
;推荐为最大的pm.max_children的%10
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 1000
request_terminate_timeout = 0
request_slowlog_timeout = 0
slowlog = /data/my_app/logs/slow.log