# Upload Issues with Nginx Reverse Proxy - Part 2

**URL:** <https://www.ruby-forum.com/t/upload-issues-with-nginx-reverse-proxy-part-2/148847>\
**Category:** NGINX\
**Created:** [September 17, 2008, 6:17pm UTC](https://www.ruby-forum.com/t/upload-issues-with-nginx-reverse-proxy-part-2/148847 "2008-09-17T18:17:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Holmes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@Tony\_Holmes](https://www.ruby-forum.com/u/Tony_Holmes)\
**Post date:** [September 17, 2008, 6:17pm UTC](https://www.ruby-forum.com/t/upload-issues-with-nginx-reverse-proxy-part-2/148847/1 "2008-09-17T18:17:12Z")

</div>

I am using nginx (0.6.29) on Freebsd 7 amd64 as a reverse proxy to back  
end  
web sites. It works very well except for php based file uploads.

I googled and found mention of setting the max post/upload/body size on  
the  
php and front end nginx.con and verified that they are correct:

php.ini:

upload\_max\_filesize = 2M  
post\_max\_size = 3M  
upload\_tmp\_dir = /tmp

nginx.conf: $server is pulled from a map, it maps the host name to  
backend  
server

```
    location / {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_redirect off;
            proxy_pass http://$server$request_uri;

            client_max_body_size 2M;
            client_body_buffer_size 2M;

            proxy_buffering off;

            proxy_connect_timeout 5;
            proxy_send_timeout 90;
            proxy_read_timeout 120;

            proxy_pass_header Expires;
            proxy_pass_header Cache-Control;
            proxy_pass_header Last-Modified;
            proxy_pass_header ETag;
            proxy_pass_header Content-Length;

    }

```

When I do the upload, the temp file does not end up in /tmp although I  
do  
see that the folder is touched (time incremented to the time of the  
upload).

Am I missing anything simple? I’m stumped and been working on this on  
and  
off for 4 days now.

---

<div class="post-metadata">

**Author:** ![Tony\_Holmes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@Tony\_Holmes](https://www.ruby-forum.com/u/Tony_Holmes)\
**Post date:** [September 22, 2008, 4:20am UTC](https://www.ruby-forum.com/t/upload-issues-with-nginx-reverse-proxy-part-2/148847/2 "2008-09-22T04:20:04Z")

</div>

I don’t have enough information on what you are trying to do to fully  
diagnose your issue, but I do have some notes on uploading with nginx  
that may help.

Nginx will fully buffer an upload before passing it to the backend  
server, depending on how you look at it this is annoying or very  
helpful. As far as I can see, it creates a file in /tmp/ something  
like /tmp/upload\_0000, starts writing to the file, and then  
immediately deletes it. The file still remains open as long as a  
process is connected to it (this is a \*nix filesystem feature so you  
can’t delete a file that is in use and crash things?). After its  
buffered to disk nginx re-reads it and hurls the whole thing to your  
backend. If this isn’t what you want (maybe nginx is on the same  
server anyways so no point in writing, reading and then writing it  
again) you might want to look at the upload module  
([http://www.grid.net.ru/nginx/upload.en.html](http://www.grid.net.ru/nginx/upload.en.html)) that lets you instruct  
nginx to write the file to a folder and then pass to your backend a  
pointer to its location.

---

<div class="post-metadata">

**Author:** ![Tony\_Holmes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@Tony\_Holmes](https://www.ruby-forum.com/u/Tony_Holmes)\
**Post date:** [September 22, 2008, 5:38am UTC](https://www.ruby-forum.com/t/upload-issues-with-nginx-reverse-proxy-part-2/148847/3 "2008-09-22T05:38:25Z")

</div>

We are goint to adopt nginx with SSL as our system front like following:  
Client ------| |–\>HTTP Server  
|–\>Nginx+SSL—\>| --\> TCP proxy  
Client ------| |—\> TCP Proxy

Who have the similar experience. I’d like to know the  
stability,performance,  
hardware configuration, etc

My Hardware env : 2G RAM Pentium® M processor 2.00GHz  
1G RAM Pentium® M processor 1.60GHz

Best regard

---

<div class="post-metadata">

**Author:** ![Tony\_Holmes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@Tony\_Holmes](https://www.ruby-forum.com/u/Tony_Holmes)\
**Post date:** [September 2, 2009, 7:11am UTC](https://www.ruby-forum.com/t/upload-issues-with-nginx-reverse-proxy-part-2/148847/4 "2009-09-02T07:11:52Z")

</div>

W. andrew Loe iii wrote:

> I don’t have enough information on what you are trying to do to fully  
> diagnose your issue, but I do have some notes on uploading with nginx  
> that may help.
> 
> Nginx will fully buffer an upload before passing it to the backend  
> server, depending on how you look at it this is annoying or very  
> helpful. As far as I can see, it creates a file in /tmp/ something  
> like /tmp/upload\_0000, starts writing to the file, and then  
> immediately deletes it. The file still remains open as long as a  
> process is connected to it (this is a \*nix filesystem feature so you  
> can’t delete a file that is in use and crash things?). After its  
> buffered to disk nginx re-reads it and hurls the whole thing to your  
> backend. If this isn’t what you want (maybe nginx is on the same  
> server anyways so no point in writing, reading and then writing it  
> again) you might want to look at the upload module  
> ([http://www.grid.net.ru/nginx/upload.en.html](http://www.grid.net.ru/nginx/upload.en.html)) that lets you instruct  
> nginx to write the file to a folder and then pass to your backend a  
> pointer to its location.

I was wondering if it is possible to turn off fully buffering the  
upload, and allowing the upload to stream to the backend servers? I have  
not seen a way to turn it off in the documentation. When we tried to put  
in nginx, it broke the file upload progress monitor, and also other  
checks we do prior to handling the upload request.

The upload module looks interesting to prevent double file writing, but  
would not solve the above issues.

---

<div class="post-metadata">

**Author:** ![Tony\_Holmes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@Tony\_Holmes](https://www.ruby-forum.com/u/Tony_Holmes)\
**Post date:** [September 2, 2009, 11:39am UTC](https://www.ruby-forum.com/t/upload-issues-with-nginx-reverse-proxy-part-2/148847/5 "2009-09-02T11:39:39Z")

</div>

Igor S. wrote:

> On Wed, Sep 02, 2009 at 07:11:52AM +0200, Simon Evans wrote:
> 
> > > process is connected to it (this is a \*nix filesystem feature so you  
> > > I was wondering if it is possible to turn off fully buffering the  
> > > upload, and allowing the upload to stream to the backend servers? I have  
> > > not seen a way to turn it off in the documentation. When we tried to put  
> > > in nginx, it broke the file upload progress monitor, and also other  
> > > checks we do prior to handling the upload request.
> 
> No. I planed nginx as accelerator only which should minimize backend  
> interaction with client. However, now I’m going to change this.

Thanks for the response Igor. I understand your plan. If we were  
starting from scratch, we would build around nginx and its modules. And  
in the future we can move logic into the nginx tier. But for now, we  
just want to insert nginx. I see the feature request in there for  
disable buffering without a priority ☹

---

<div class="post-metadata">

**Author:** ![Tony\_Holmes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@Tony\_Holmes](https://www.ruby-forum.com/u/Tony_Holmes)\
**Post date:** [September 2, 2009, 7:49am UTC](https://www.ruby-forum.com/t/upload-issues-with-nginx-reverse-proxy-part-2/148847/6 "2009-09-02T07:49:25Z")

</div>

On Wed, Sep 02, 2009 at 07:11:52AM +0200, Simon Evans wrote:

> > process is connected to it (this is a \*nix filesystem feature so you  
> > I was wondering if it is possible to turn off fully buffering the  
> > upload, and allowing the upload to stream to the backend servers? I have  
> > not seen a way to turn it off in the documentation. When we tried to put  
> > in nginx, it broke the file upload progress monitor, and also other  
> > checks we do prior to handling the upload request.

No. I planed nginx as accelerator only which should minimize backend  
interaction with client. However, now I’m going to change this.

---

<div class="post-metadata">

**Author:** ![Tony\_Holmes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@Tony\_Holmes](https://www.ruby-forum.com/u/Tony_Holmes)\
**Post date:** [October 31, 2010, 3:28pm UTC](https://www.ruby-forum.com/t/upload-issues-with-nginx-reverse-proxy-part-2/148847/7 "2010-10-31T15:28:30Z")

</div>

Hi

I got the same problem as this. but I am using 0.8.53 already. I need a  
reverse proxy to upload big files to a backend server and it always got  
time out with big files.  
I have set the proxy\_buffering off already but didnt help. Is there a  
way to make it direct upload through nginx already now?

many many thanks

Posted at Nginx Forum:

> **[Re: Upload Issues with Nginx Reverse Proxy - Part 2](https://forum.nginx.org/read.php?2,5506,146254)**
>
> W. andrew Loe iii wrote: \> I don't have enough information on what you are trying to do to fully \> diagnose your issue, but I do have some notes on uploading with nginx \> that may help. \> \> Nginx will fully buffer an upload before...
