# Uploads with nginx 1.0.12

**URL:** <https://www.ruby-forum.com/t/uploads-with-nginx-1-0-12/217402>\
**Category:** NGINX\
**Created:** [February 29, 2012, 9:00pm UTC](https://www.ruby-forum.com/t/uploads-with-nginx-1-0-12/217402 "2012-02-29T21:00:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 29, 2012, 9:00pm UTC](https://www.ruby-forum.com/t/uploads-with-nginx-1-0-12/217402/1 "2012-02-29T21:00:20Z")

</div>

Hello,

I am using file uploads with nginx 1.0.12, php5-fpm and php 5.3.10.

Currently, big file uploads (~1300 MB) do take about 30 seconds to  
process  
after the file is being uploaded, and the CPU load spikes. Is there a  
way  
to prevent that?

I am using a very simple script (just a var\_dump($\_FILES), nothing more,  
just debugging) and the config looks like the following:  
location ~ .php$ {  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_pass\_request\_body off;  
client\_body\_in\_file\_only clean;  
fastcgi\_param REQUEST\_BODY\_FILE $request\_body\_file;  
fastcgi\_send\_timeout 120;  
fastcgi\_read\_timeout 120;  
fastcgi\_index index.php;  
include fastcgi\_params;  
}

Hope that someone can shed light into this…

Thank you.

Adrian

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 29, 2012, 9:36pm UTC](https://www.ruby-forum.com/t/uploads-with-nginx-1-0-12/217402/2 "2012-02-29T21:36:15Z")

</div>

On Wed, 2012-02-29 at 20:59 +0100, Adrián Navarro wrote:

> Hello,
> 
> I am using file uploads with nginx 1.0.12, php5-fpm and php 5.3.10.
> 
> Currently, big file uploads (~1300 MB) do take about 30 seconds to  
> process after the file is being uploaded, and the CPU load spikes. Is  
> there a way to prevent that?

I assume that since the spike occurs _after_ the upload, the culprit is  
PHP, not Nginx?

> I am using a very simple script (just a var\_dump($\_FILES), nothing  
> more,

Assuming the spike is caused by PHP, you might take a look at the  
nginx\_upload module, which will handle the entire upload process for  
you, and just hand your PHP script a path to the uploaded file (along  
with a few other parameters).

Here’s some references:

> **[Optimized File Uploading With PHP & Nginx](https://blog.martinfjordvald.com/file-uploading-with-php-and-nginx/)**
>
> Performance is often important to people using Nginx - and for good reason, of course. Sadly, while many people will optimize their software stack they will rarely work on optimizing the back-end code; and even more rarely will they eliminate single...

[http://brainspl.at/articles/2008/07/20/nginx-upload-module](http://brainspl.at/articles/2008/07/20/nginx-upload-module)

[https://github.com/vkholodkov/nginx-upload-module/tree/2.2](https://github.com/vkholodkov/nginx-upload-module/tree/2.2)

Regards,  
Cliff

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 29, 2012, 9:49pm UTC](https://www.ruby-forum.com/t/uploads-with-nginx-1-0-12/217402/3 "2012-02-29T21:49:54Z")

</div>

Indeed, the high load is caused by php-fpm. I was wondering if there was  
any alternative config to keep fpm from spiking (like, any built-in  
helper  
to pass the final location without any plugin…).

I will look into the compiled module. I’m not very comfortable with  
compiling it on the cluster of servers which were previously using  
dotdeb,  
but it’s better than nothing (uh, tips to keep the debian specific  
structure when compiling?).

Thanks for pointing me out!

-Adrian

---------- Forwarded message ----------  
From: Cliff W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: Wed, Feb 29, 2012 at 9:35 PM  
Subject: Re: Uploads with nginx 1.0.12  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

On Wed, 2012-02-29 at 20:59 +0100, Adrián Navarro wrote:

> Hello,
> 
> I am using file uploads with nginx 1.0.12, php5-fpm and php 5.3.10.
> 
> Currently, big file uploads (~1300 MB) do take about 30 seconds to  
> process after the file is being uploaded, and the CPU load spikes. Is  
> there a way to prevent that?

I assume that since the spike occurs _after_ the upload, the culprit is  
PHP, not Nginx?

> I am using a very simple script (just a var\_dump($\_FILES), nothing  
> more,

Assuming the spike is caused by PHP, you might take a look at the  
nginx\_upload module, which will handle the entire upload process for  
you, and just hand your PHP script a path to the uploaded file (along  
with a few other parameters).

Here’s some references:

> **[Optimized File Uploading With PHP & Nginx](https://blog.martinfjordvald.com/file-uploading-with-php-and-nginx/)**
>
> Performance is often important to people using Nginx - and for good reason, of course. Sadly, while many people will optimize their software stack they will rarely work on optimizing the back-end code; and even more rarely will they eliminate single...

[http://brainspl.at/articles/2008/07/20/nginx-upload-module](http://brainspl.at/articles/2008/07/20/nginx-upload-module)

[https://github.com/vkholodkov/nginx-upload-module/tree/2.2](https://github.com/vkholodkov/nginx-upload-module/tree/2.2)

Regards,  
Cliff

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 29, 2012, 10:31pm UTC](https://www.ruby-forum.com/t/uploads-with-nginx-1-0-12/217402/4 "2012-02-29T22:31:34Z")

</div>

On Wed, 2012-02-29 at 21:48 +0100, Adrián Navarro wrote:

> Indeed, the high load is caused by php-fpm. I was wondering if there  
> was any alternative config to keep fpm from spiking (like, any  
> built-in helper to pass the final location without any plugin…).
> 
> I will look into the compiled module. I’m not very comfortable with  
> compiling it on the cluster of servers which were previously using  
> dotdeb, but it’s better than nothing (uh, tips to keep the debian  
> specific structure when compiling?).

If you are comfortable building .deb packages, you could just rebuild  
the .deb with the additional module built in.

Alternatively, you could use the output of “nginx -V” to get a list of  
compile-time options and use those when building from source.

In either case, I would make an archive of your /etc/nginx directory  
just to be safe. I’d also strongly suggest doing a test build outside  
of your cluster. In general, building Nginx from source is fairly  
simple, but always better to be cautious.

Regards,  
Cliff

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 29, 2012, 10:42pm UTC](https://www.ruby-forum.com/t/uploads-with-nginx-1-0-12/217402/5 "2012-02-29T22:42:45Z")

</div>

On Thursday 01 March 2012 00:35:51 Cliff W. wrote:

> 

Actually,

fastcgi\_pass\_request\_body off;  
client\_body\_in\_file\_only clean;  
fastcgi\_param REQUEST\_BODY\_FILE $request\_body\_file;

should do approximately the same.

wbr, Valentin V. Bartenev
