Upload Issues with Nginx Reverse Proxy - Part 2

W. Andrew Loe III andrew at andrewloe.com
Mon Sep 22 06:08:31 MSD 2008

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) that lets you instruct
nginx to write the file to a folder and then pass to your backend a
pointer to its location.

On Wed, Sep 17, 2008 at 7:59 AM, Tony Holmes <atholmes at gmail.com> wrote:
> 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.

More information about the nginx mailing list