2

We have a Python Flask API running in gunicorn being fronted by apache.

ProxyPreserveHost On
<Location /api/v2>
    ProxyPass http://127.0.0.1:8090/ disablereuse=on
    SetEnv proxy-sendcl
</Location>

The python API is configured to raise a 413 if a file over a certain size is uploaded. When hitting the python API directly the response is returned correctly, however when apache is added to the mix, a 502 is returned with no errors in the apache error log.

user@server:~$ curl -v -X POST   http://localhost:8090/photos -F [email protected]
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8090 (#0)
> POST /photos HTTP/1.1
> Host: localhost:8090
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 31457564
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------5333e9e102a557ee
>
< HTTP/1.1 100 Continue
< HTTP/1.1 413 REQUEST ENTITY TOO LARGE
< Server: gunicorn/19.6.0
< Date: Fri, 21 Sep 2018 18:38:09 GMT
< Connection: close
< Content-Type: application/json
< Content-Length: 76
<
{
    "message": "The data value transmitted exceeds the capacity limit."
}
* we are done reading and this is set to close, stop send
* Closing connection 0

And here is the 502 happening when apache is proxy:

$ curl -v -X POST \
  https://my.servers.com/photos \
  -F [email protected]
*   Trying xx.xx.xx.xxx...
* TCP_NODELAY set
* Connected to my.server.com (xx.xx.xx.xxx) port 443 (#0)
... SSL ...
> POST /api/v2/photos HTTP/1.1
> Host: my.servers.com
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Length: 42716348
> Expect: 100-continue
> Content-Type: application/x-www-form-urlencoded; boundary=------------------------5bc19156b7a56f0e
>
* Done waiting for 100-continue
< HTTP/1.1 502 Bad Gateway
< Date: Fri, 21 Sep 2018 20:21:13 GMT
< Server: Apache
< Content-Length: 232
< Content-Type: text/html; charset=iso-8859-1
* HTTP error before end of send, stop sending
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Bad Gateway</title>
</head><body>
<h1>Bad Gateway</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
</p>
</body></html>
* Closing connection 0
* TLSv1.2 (OUT), TLS alert, Client hello (1):

What I've tried:

Any ideas why Apache won't pass the 413 along?

1 Answer 1

0

I'm going to list the issues I see in order of appearance.

Your server (running PHP) is expecting "Content-Type: multipart/form-data." It looks like it sends "Content-Type: application/json."

Your proxy is sending content type "Content-Type: application/x-www-form-urlencoded" to the server that is expecting "Content-Type: multipart/form-data."

My first question would be, if a file of the correct (acceptable) size is sent through the Apache Proxy, does the server (running PHP) handle the file correctly?

If this isn't happening the Apache proxy is going to see an "HTTP error before end of send, stop sending" because the server (the one running PHP) isn't going to recognize the content type and throw an error (the invalid response based on content type) and present a 502 to the client instead of passing through the 413.

Does this line of configuration in the proxy (you'll need to configure the FQDN to your destination and optimize the variables) fix your problem (after establishing that the destination server handles the correctly sized/formatted graphic, correctly)?

ProxyPass / http://localhost:8090/ retry=1 acquire=3000 timeout=600 Keepalive=On

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .