Nginx – 500 errors when uploading large files with fastcgi

apache-2.2fastcginginx

I am using the following setup:

  • CentOS 5.9
  • Apache with Nginx proxy for static resources
  • PHP 5.4
  • fastcgi

When uploading smaller files, everything works fine. If however I try to upload larger files (I haven't yet determined the cut off point) I get 500 errors.

My apache logs are set to E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

When this first occurred I checked the logs and saw that the POST was longer than the MaxRequestLen in fcgi config.

I promptly changed this in both my php.conf file and in my post_virtualHost include file from within cPanel. This prevented the error message from getting logged but i still receive the 500 errors, and confusingly, no errors relating to this are getting logged whatsoever.

From the clients point of view the file seems to upload fine and takes a long as it should (with html5 file api reporting the progress correctly throughout) and the 500 error is generated after the server has received the full file during a lengthy script execution afterwards.

The file itself is a large text file containing several base64 images which are then pulled apart server side, converted into actual image files using ImageMajick (via the IMajik php extension) and are then duplicated into several different size versions with varying levels of filtering/compression applied to them. This whole process can take quite some time. Could this be part of the problem? If so how would I fix it?

My fcgi configuration is current as follows:

MaxRequestsPerProcess 1000
FcgidMaxProcesses 200
FcgidProcessLifeTime 7200
MaxProcessCount 500
FcgidIOTimeout 400
FcgidIdleTimeout 600
FcgidIdleScanInterval 90
FcgidBusyTimeout 300
FcgidBusyScanInterval 80
ErrorScanInterval 3
ZombieScanInterval 3
DefaultMinClassProcessCount 0
DefaultMaxClassProcessCount 3
FcgidMaxRequestLen  1073741824

I have tried replacing FcgidMaxRequestLen with the older MaxRequestLen but still no luck.

Any help would be greatly appreciated.

Best Answer

Any chance that your script simply times out? FcgidBusyTimeout is 5 minutes — maybe it isn't enough when several scripts are running concurrently.

Why do you use fcgi instead of mod_php? If you use ngix as a reverse proxy and for serving static content then fcgi is just another layer of complexity: ngix+apache is good, apache+fcgi is good, ngix+fcgi is good, ngix+apache+fcgi does not make sense.