502 Bad Gateway when downloading file

Hello all.
I have topology as follows:
client->NGINX->haproxy-> 4xapache servers.

Problem is, that on one page, we have option to download file - it is
done through changing header. Resulting header is as follows:
Content-type: application/txt

Content-Length: “xxxxx”

Content-Disposition: attachment; filename=“aaa.txt”

I’m getting 502 Bad Gateway, The server returned an invalid or
incomplete response error everytime after clicking on link. In logs,
there is nothing weird. When trying it directly through HAPROXY or
directly through nginx (pointed to one of that apache servers) it is
working correctly.

Do you have any idea about how to resolve it? Have anybody experienced
something like this?
Many thanks for any reply concerning this.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,216759,216759#msg-216759

On Sat, Oct 15, 2011 at 7:51 PM, sogi [email protected] wrote:

Hello all.
I have topology as follows:
client->NGINX->haproxy-> 4xapache servers.

Problem is, that on one page, we have option to download file - it is
done through changing header. Resulting header is as follows:
Content-type: application/txt

how do you change header, and can you please post complete headers
from successful request[s] and from unsuccessful request?

Content-Length: “xxxxx”

Content-Disposition: attachment; filename=“aaa.txt”

I’m getting 502 Bad Gateway, The server returned an invalid or
incomplete response error everytime after clicking on link. In logs,
there is nothing weird.

please post any relevant log entries

When trying it directly through HAPROXY or

directly through nginx (pointed to one of that apache servers) it is
working correctly.

we need to see the headers

Do you have any idea about how to resolve it? Have anybody experienced
something like this?
Many thanks for any reply concerning this.

Stefan C.

Hello.
Many thanks for your reply.
We are changing headers through PHP header() function.

Header is dispatching correctly from HAPROXY. It is as follows:
HTTP/1.1 200 OK

Date: Fri, 14 Oct 2011 01:18:08 GMT

Server: Apache/2.2.16 (Debian)

X-Powered-By: PHP/5.2.10

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0

Pragma: no-cache

Content-Length: 77032;

Content-Disposition: attachment; filename=“aaaa.txt”

Connection: close

Content-Type: application/txt

Logs from nginx debug:
http://pastebin.com/UrMXgYyf
(I have more - all from logging into system to 502, but there are so
large actually :slight_smile: )

Actually, I don’t have any successful header…
Let me know if you want something, I can debug/prepare it if you need
more informations.
Many thanks for all the help.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,216759,216774#msg-216774

mmm you are the man :slight_smile:
Well, its confirmed now - it is working when I removed ; from header. I
missed it before…
Great - many thanks again - you made my day :slight_smile:

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,216759,216779#msg-216779

Hello!

On Sun, Oct 16, 2011 at 07:24:34AM -0400, sogi wrote:

pre-check=0

Pragma: no-cache

Content-Length: 77032;

The “;” is incorrect and shouldn’t be here. If it’s indeed
present in headers returned by your backend - there is no surprise
haproxy rejects such responses (see below).

Logs from nginx debug:
http://pastebin.com/UrMXgYyf
(I have more - all from logging into system to 502, but there are so
large actually :slight_smile: )

Debug log shows response from backend was already 502:

2011/10/13 21:47:05 [debug] 15881#0: *33 http proxy status 502 “502 Bad
Gateway”

That is, most likely it’s haproxy who returned 502. See above for
possible reason.

Maxim D.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs