502 Bad gateway on big file uploads : Nginx + PHP-FPM

ryan asked:

I’m running php-fpm on nginx

I have my php.ini values set as follows

upload_max_filesize = 100M
post_max_size = 128M
max_execution_time = 180

I have also set my client_max_body_size to 4G. When I try small uploads they work, but when I try a big upload of say 35M I get a 502 and when I look through the logs I see ,

upstream sent unexpected FastCGI record: 3 while reading response header from upstream

Any ideas? I’ve tried the nginx threads but they don’t really help.

Thanks in advance

My answer:

First step: ensure you have error logging enabled in php.ini and check the log entries.

From your log entry:

WARNING: [pool www] child 920 said into stderr: "NOTICE: PHP message: PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 39277825 bytes) in Unknown on line 0"

It appears PHP has run out of memory processing the uploaded file. You will need to increase the memory_limit parameter. Further information on upload tuning can be found at the PHP web site.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.