nginx+php设置大文件请求上传(502及504问题处理)

502问题

  • php-fpm

修改项: 

request_terminate_timeout 

位置:

eg: /etc/php5/fpm2/pool.d/www.conf
; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_terminate_timeout = 300s

这个注释说明了,request_terminate_timeout 适用于,当max_execution_time由于某种原因无法终止脚本的时候,会把这个php-fpm请求干掉。
再看看max_execution_time的注释:这设置了脚本被解析器中止之前允许的最大执行时间,默认是30s。看样子,我这个请求应该是被max_execution_time这个设置干掉了。

 

  • php.ini

修改项:

  max_execution_time 

位置:

eg: /etc/php5/fpm2/php.ini
; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 300
  • 重启

service php5-fpm restart

 

总结:

web请求php执行时间受到2方面控制,一个是php.ini的max_execution_time(要注意的是sleep,http请求等待响应的时间是不算的,这里算的是真正的执行时间),另一个是php-fpm request_terminate_timeout 设置,这个算的是请求开始n秒。

 


 

504问题

处理项:

  fastcgi_read_timeout

位置:

  /etc/nginx/sites-enabled/default

  • 重启

/usr/sbin/nginx -s reload

 

备注:

php.ini 开启:post_max_size,upload_max_filesize,nginx,memory_limit,max_execution_time

如果修改不生效,查看  /etc/php5/fpm2/pool.d/www.conf  中配置

 

杀掉进程,确保php服务重新启动相关进程

pkill php5-fpm

 

 

参考地址:

https://blog.csdn.net/loophome/article/details/78604986

https://blog.csdn.net/lifei15731208550/article/details/89056867

posted on 2019-08-07 10:46  爱吃柠檬不加糖  阅读(3815)  评论(0编辑  收藏  举报

导航