How can I do nginx rewrite?

How do I upload GB files with Nginx + PHP, if it aborts when handing over from Nginx to PHP?

  • Okay, what I'm trying to achieve, is to be able to upload files that are several GB of size. I've set up a VM for testing purposes, with CentOS, 2Gb RAM, 40Gb disk that runs Nginx 1.0.15 and PHP 5.5.4 (fpm-fcgi). In the nginx site file, I have: location ~ \.php$ { fastcgi_pass   127.0.0.1:9000;         fastcgi_index  index.php;         fastcgi_param  SCRIPT_FILENAME  /home/sites/upload/www$fastcgi_script_name;         include        fastcgi_params;         client_max_body_size 0;         client_body_timeout 3600;         client_body_temp_path      /tmp/;         client_body_in_file_only   on;         client_body_buffer_size    128K; } In php.ini I've set/changed: max_execution_time = 300 memory_limit = 1280M post_max_size = 100000M file_uploads = On upload_max_filesize = 100000M I have reloaded both nginx and php-fpm. Files up to a certain size, max 4.05G, uploads and is moved to the final location. Larger files fails. The /tmp folder is used for both nginx temp files (i.e. 0000000007) and php temp files (i.e. phpGZxePg), so that it's easy to watch (# watch ls -lh) what is going on, both on successful and failed uploads. On a successful upload, an nginx temp file is created, i.e. 0000000007, and the size increases until everything is uploaded from the browser. Then, a php temp file i being created, i.e. phpGZxePg, It seems that it reads the 0000000007 file and writes to the php temp file. The, the file is being moved to the final location. On a failed upload, 0000000007 fills successfully. The php creates a temp file, but gives up after just a few mb (varies from nothing to to a few hundred mb) Strangely when the file is just above 4.05, almost no php temp data is generated, but on 5gb, about 600 mb of php temp data is created. So, it seems like php trying to read & parse the uploaded/body data from nginx by read it into memory/swap maybe, and when not enough resources are available, it gives up, returning error: 3. Are there any way around this issue? I've been using apache (LAMP) before, and there it seem that the php temp file is created during upload, not after. Is that possible to achieve here as well? Any other ways to do this? Could for example the Nginx Upload Module make any difference? Would it work with a SabreDAV implementation? Thanks!

  • Answer:

    You may also want to check the max_input_time and max_execution time. It could be that the max size is fine but it's taking too long to upload and failing.

Kwan Lowe at Quora Visit the source

Was this solution helpful to you?

Other answers

FYI: Unfortunately, we ended up going back to Apache. However, I'll keep the VM in case some interesting solution shows up :)

Morten Tangerås

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.