# File upload issue with Nginx (Reverse proxy+SSL negotiation) and Tomcat

**URL:** <https://www.ruby-forum.com/t/file-upload-issue-with-nginx-reverse-proxy-ssl-negotiation-and-tomcat/236019>\
**Category:** NGINX\
**Created:** [July 31, 2013, 2:21am UTC](https://www.ruby-forum.com/t/file-upload-issue-with-nginx-reverse-proxy-ssl-negotiation-and-tomcat/236019 "2013-07-31T02:21:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [July 31, 2013, 2:21am UTC](https://www.ruby-forum.com/t/file-upload-issue-with-nginx-reverse-proxy-ssl-negotiation-and-tomcat/236019/1 "2013-07-31T02:21:40Z")

</div>

Configuration:

==========

- Nginx as reverse proxy + SSL negotiation

- Apache Tomcat.

- nginx version: nginx/1.5.2  
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-54)  
TLS SNI support disabled  
configure arguments: --with-rtsig\_module --with-select\_module  
–with-poll\_module --with-file-aio --with-http\_ssl\_module  
–with-http\_realip\_module --with-http\_addition\_module  
–with-http\_xslt\_module --with-http\_image\_filter\_module  
–with-http\_geoip\_module --with-http\_sub\_module --with-http\_dav\_module  
–with-http\_flv\_module --with-http\_mp4\_module  
–with-http\_gzip\_static\_module --with-http\_random\_index\_module  
–with-mail  
–with-mail\_ssl\_module --with-cpp\_test\_module --with-pcre  
–with-libatomic  
–with-debug  
==========

Everything seems to work fine, except for the file upload. For some  
reason  
file upload never completes. With the configuration listed below, I am  
able  
to upload small files (4K). Upload fails on a 194K file. When I increase  
“client\_body\_buffer\_size” to 256K, I can upload the 194K file, but a  
500K  
file upload fails. Increasing “client\_body\_buffer\_size” beyond 256K has  
no  
impact.

**Note: When I access Tomcat directly and upload the 500K file, it  
finishes  
in a few milliseconds.**

So, looks like something is wrong with Nginx configuration. Any  
suggestions  
are greatly appreciated.

location / {  
root /xyz;  
proxy\_pass [http://127.0.0.1:9090](http://127.0.0.1:9090);  
proxy\_redirect off;  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-Server $host;  
proxy\_intercept\_errors on;

proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
client\_max\_body\_size 500m;  
client\_body\_buffer\_size 128k;  
proxy\_buffering on;  
proxy\_connect\_timeout 75;  
proxy\_send\_timeout 180;  
proxy\_read\_timeout 180;  
proxy\_buffer\_size 128k;  
proxy\_buffers 4 256k;  
proxy\_busy\_buffers\_size 256k;  
proxy\_temp\_file\_write\_size 64k;

}

I have tried adding several other parameters to nginx config  
(client\_body\_temp\_path, proxy\_temp\_path, proxy\_temp\_file\_write\_size).  
They  
didn’t seem to help.

====

\*\*\*\*\* Further investigation revealed that we have problem uploading 196K  
file and upwards. 194K file works. “client\_body\_buffer\_size” value is  
set  
to 256K.

# Nginx debug logs show the following in case of failue:

2013/07/30 16:29:57 [debug] 14208#0: \*1 recv: fd:11 2606 of 16384  
2013/07/30 16:29:57 [debug] 14208#0: \*1 http proxy status 200 “200 OK”  
2013/07/30 16:29:57 [debug] 14208#0: \*1 http proxy header: “Server:  
Apache-Coyote/1.1”  
2013/07/30 16:29:57 [debug] 14208#0: \*1 http proxy header:  
“Content-Type:  
text/html;charset=utf-8”  
2013/07/30 16:29:57 [debug] 14208#0: \*1 http proxy header: “Date: Tue,  
30  
Jul 2013 22:29:57 GMT”  
2013/07/30 16:29:57 [debug] 14208#0: \*1 http proxy header: “Connection:  
close”  
2013/07/30 16:29:57 [debug] 14208#0: \*1 http proxy header done  
2013/07/30 16:29:57 [debug] 14208#0: \*1 xslt filter header  
2013/07/30 16:29:57 [debug] 14208#0: \*1 HTTP/1.1 200 OK^M  
Server: nginx/1.5.2^M  
Date: Tue, 30 Jul 2013 22:29:57 GMT^M  
Content-Type: text/html;charset=utf-8^M  
Transfer-Encoding: chunked^M  
Connection: keep-alive^M

# 2013/07/30 16:29:57 [debug] 14208#0: \*1 write new buf t:1 f:0 000000001E61DAD8, pos 000000001E61DAD8, size: 168 file: 0, size: 0 2013/07/30 16:29:57 [debug] 14208#0: \*1 http write filter: l:0 f:0 s:168 2013/07/30 16:29:57 [debug] 14208#0: \*1 http cacheable: 0 2013/07/30 16:29:57 [debug] 14208#0: \*1 posix\_memalign: 000000001E62D450:4096 @16 2013/07/30 16:29:57 [debug] 14208#0: \*1 http proxy filter init s:200 h:0 c:0 l:-1 2013/07/30 16:29:57 [debug] 14208#0: \*1 http upstream process upstream 2013/07/30 16:29:57 [debug] 14208#0: \*1 pipe read upstream: 1 2013/07/30 16:29:57 [debug] 14208#0: \*1 pipe preread: 2465 2013/07/30 16:29:57 [debug] 14208#0: \*1 readv: 1:13778 2013/07/30 16:29:57 [debug] 14208#0: \*1 readv() not ready (11: Resource temporarily unavailable) 2013/07/30 16:29:57 [debug] 14208#0: \*1 pipe recv chain: -2 2013/07/30 16:29:57 [debug] 14208#0: \*1 pipe buf free s:0 t:1 f:0 000000001E61DBD0, pos 000000001E61DC5D, size: 2465 file: 0, size: 0 2013/07/30 16:29:57 [debug] 14208#0: \*1 pipe length: -1 2013/07/30 16:29:57 [debug] 14208#0: \*1 pipe write downstream: 1 2013/07/30 16:29:57 [debug] 14208#0: \*1 pipe write busy: 0 2013/07/30 16:29:57 [debug] 14208#0: \*1 pipe write: out:0000000000000000, f:0 2013/07/30 16:29:57 [debug] 14208#0: \*1 pipe read upstream: 0 2013/07/30 16:29:57 [debug] 14208#0: \*1 pipe buf free s:0 t:1 f:0 000000001E61DBD0, pos 000000001E61DC5D, size: 2465 file: 0, size: 0 2013/07/30 16:29:57 [debug] 14208#0: \*1 pipe length: -1 2013/07/30 16:29:57 [debug] 14208#0: \*1 event timer add: 11: 180000:1375223577332 2013/07/30 16:29:57 [debug] 14208#0: \*1 http upstream request: “/upload/html?” 2013/07/30 16:29:57 [debug] 14208#0: \*1 http upstream send request handler 2013/07/30 16:29:57 [debug] 14208#0: timer delta: 6 2013/07/30 16:29:57 [debug] 14208#0: posted events 0000000000000000 2013/07/30 16:29:57 [debug] 14208#0: worker cycle 2013/07/30 16:29:57 [debug] 14208#0: epoll timer: 179994

I notice “http upstream send request handler” in above log snippet,  
where  
as in success case, I see this:  
2013/07/30 16:29:44 [debug] 14208#0: \*1 http upstream dummy handler

Any idea what “http upstream send request handler” and “http upstream  
dummy  
handler” mean, and what they signify?

---

<div class="post-metadata">

**Author:** ![Kiran\_Pillarisetty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@Kiran\_Pillarisetty](https://www.ruby-forum.com/u/Kiran_Pillarisetty)\
**Post date:** [July 31, 2013, 10:01am UTC](https://www.ruby-forum.com/t/file-upload-issue-with-nginx-reverse-proxy-ssl-negotiation-and-tomcat/236019/2 "2013-07-31T10:01:28Z")

</div>

Hello!

On Tue, Jul 30, 2013 at 05:21:09PM -0700, Kiran Pillarisetty wrote:

> –with-poll\_module --with-file-aio --with-http\_ssl\_module  
> Everything seems to work fine, except for the file upload. For some reason  
> are greatly appreciated.  
> proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;
> 
> # \*\*\*\*\* Further investigation revealed that we have problem uploading 196K text/html;charset=utf-8" Transfer-Encoding: chunked^M 2013/07/30 16:29:57 [debug] 14208#0: \*1 http upstream process upstream 2013/07/30 16:29:57 [debug] 14208#0: \*1 pipe write busy: 0 2013/07/30 16:29:57 [debug] 14208#0: \*1 http upstream send request handler 2013/07/30 16:29:57 [debug] 14208#0: timer delta: 6 2013/07/30 16:29:57 [debug] 14208#0: posted events 0000000000000000 2013/07/30 16:29:57 [debug] 14208#0: worker cycle 2013/07/30 16:29:57 [debug] 14208#0: epoll timer: 179994

From a debug log fragment provided it’s not clear what goes wrong,  
you may want to show full debug log.

My best guess is that your backend tries to respond to a request  
before it actually read a request. In such a case nginx will stop  
sending a request (if there is anything left), but your backend  
needs it to complete the response. Hence timeout.

> I notice “http upstream send request handler” in above log snippet, where  
> as in success case, I see this:  
> 2013/07/30 16:29:44 [debug] 14208#0: \*1 http upstream dummy handler
> 
> Any idea what “http upstream send request handler” and “http upstream dummy  
> handler” mean, and what they signify?

You may try looking into sources to find out.

–  
Maxim D.  
[http://nginx.org/en/donation.html](http://nginx.org/en/donation.html)

---

<div class="post-metadata">

**Author:** ![Kiran\_Pillarisetty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@Kiran\_Pillarisetty](https://www.ruby-forum.com/u/Kiran_Pillarisetty)\
**Post date:** [July 31, 2013, 11:55pm UTC](https://www.ruby-forum.com/t/file-upload-issue-with-nginx-reverse-proxy-ssl-negotiation-and-tomcat/236019/3 "2013-07-31T23:55:07Z")

</div>

Hi Maxim,

Thank you for the response. I am attaching the full debug log files  
from success and failure cases.

> … In such a case nginx will stopsending a request  
> (if there is anything left), but your backend  
> needs it to complete the response. Hence timeout.

In such scenario, how exactly could we prevent Nginx from stopping the  
sending of the file?

Also, it is interesting to note that when we access Tomcat port  
directly, we can upload the file without an issue.

Thank you!
