Upload Issues with Nginx Reverse Proxy - Part 2

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.

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.

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

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) 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.

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 :frowning:

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.

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: