Search code examples
apachetomcatmod-proxy

mod_proxy with tomcat7 gives error 502 when uploading files


So, I have an apache 2.2.16 (64 bit) installed on a Debian Server. I have configured a proxy, for a specific url to map to my backend Tomcat 7 server.

Everything works fine for all of the GET/POST requests except for multipart POST requests. The error log of apache is showing the followinf lines:

[error] [client CLIENT_IP] (20014)Internal error: proxy: error reading status line from remote server TOMCAT_IP:8081
[error] [client CLIENT_IP] proxy: Error reading from remote server returned by /svc/document

Strange thing is that POST multipart works fine if I upload a ZERO Kb file, but fails with other files (no more than a few bytes). And everything, including uploads works fine on my developing environment (XAMPP + mod_proxy + tomcat)

Tomcat 7 connector:

<Connector port="8081" protocol="HTTP/1.1" address="TOMCAT_IP" maxThreads="6000"
               connectionTimeout="40000" URIEncoding="UTF-8" maxPostSize="8388608" 
               redirectPort="8443" />

Proxy is configured as follows:

<VirtualHost *:80>
      DocumentRoot /var/www/frontend/
      ServerName frontend.com

      ProxyPass /svc/ http://[TOMCAT_IP]:8081/web/ connectiontimeout=40 timeout=60 Keepalive=On min=20 acquire=20 retry=1
 </VirtualHost>

I even tried some suggestions, one by one and all in once, as found on similar question, but with no luck:

<VirtualHost *:80>
  DocumentRoot /var/www/frontend/
  ServerName frontend.com

  ProxyPass /svc/ http://[TOMCAT_IP]:8081/web/ connectiontimeout=40 timeout=60 Keepalive=On min=20 acquire=20 retry=1

  ProxyBadHeader Ignore
  ProxyRequests Off
  LimitRequestBody 8388608
  SetEnv proxy-sendchunked 1
</VirtualHost>

I tried ProxyPassReverse, raise timeout, ProxyBadHeader Ignore, setenv proxy-initial-not-pooled 1 etc. nothing seems to work... Any idea?


Solution

  • I found the solution a while ago, I'm posting it for future reference.

    The problem was neither Tomcat nor Apache. The problem was in the underlying network. The connection between the 2 servers, provided as a separate link by the ISP was missing/had a bad MTU parameter configuration. This was causing the network to drop frames bigger than a certain number of bytes. Once the MTU was set explicitly to 1500 problem was gone.