Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.

Sponsors

News

 
 
 
 
 
DZone MVB

Links

Social

Apache, IIS and 502 proxy error

I have some servers in my network. There is one public Apache server that proxies requests to these servers. These servers are not directly visible from internet. Some of these servers run IIS and ASP.NET web applications. When accessing these servers through internet then sometimes Apache reports a problem: 502 proxy error.

After some digging in internet I found out what’s going on between Apache and IIS. There is very informative bug report in Apache issue tracker - Bug 37770 - proxy: error reading status line from remote server (null). Comment #17 states reason of error as follows:

The problem also only occurs for us when we use an IIS backend device, with an apache its ok. From a tcpdump the only diff I can see between the two sessions is that the IIS closes the connection when the keep-alive time out is reached with a TCP RST packet, while the apache does a Fin/Ack handshake. When IIS sends this RST packet the next request to the mod_proxy device that’s hits the worker with the RST connection returns the 502 error msg.

So, there is some misunderstandings between Apache proxy stuff and IIS. Although some guys suggest to use very long timeouts and hacks to Apache source code there is very simple fix that works very well for me. Make sure you have mod_env enabled and add these lines to Apache configuration file.


SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1

After restarting Apache server the communication between Apache and IIS should work fine. After these modifications I have seen no error 502 anymore.

Posted: Feb 07 2009, 02:02 PM by DigiMortal | with 16 comment(s)
Filed under: ,

Comments

Apache, IIS and 502 proxy error - Gunnar Peipman's ASP.NET blog said:

Pingback from  Apache, IIS and 502 proxy error - Gunnar Peipman's ASP.NET blog

# February 7, 2009 1:48 PM

Micah Nolte said:

This post is very timely. I just set up dev environments for me and my co-workers at my job, and this issue has been frustrating us. Many thanks.

# February 11, 2009 1:15 PM

DigiMortal said:

You are welcome :)

# February 11, 2009 1:47 PM

amir said:

interesting article abot 502 <a href=\"vpnomania.com/proxy-surf.html\">proxy</a>  error

# February 23, 2009 5:10 AM

Betty said:

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

Betty

http://laptopprocessor.info

# March 17, 2009 11:12 PM

kiran said:

Nice blog

I am facing same problem. I have done the above mentioned changes SetEnv. But still getting the same error.I am using apache 2.2.3

# August 11, 2009 6:33 AM

Justin said:

This solution worked for me, thanks for posting it

# August 26, 2009 7:17 AM

Henry said:

Good Solution.. Worked for me..

# September 3, 2009 7:03 AM

Ivan Tsui said:

Firstly, I would like to know the impact of 502 error.   When the apache act as proxy reported 502, how the apache will assume the status of IIS servers?

On other hand, the two setenv will fallback to httpd/1.0 without keepalive.   Does it may increaes the TCP sockets needed to be opened as no more keepalive?

This will increase the loading for the IIS server.

# September 21, 2009 5:19 AM

kiran said:

I am getting this error in two scenarious after this env setting is done,

if the request that is made from the browser is time taking/bigger size data as a result.

and observed if number of simultaneous requests are in the range of 5-10

Please help me

# May 14, 2010 3:27 AM

Fasih Hansmukh said:

Althu, this was written in 2009, but helped me last day. Was having same issue and was unable to find root couse. This helps. Thanks a lot and keep up the good things.

# May 10, 2011 7:40 AM

Eric said:

Great! This is exactly what I was looking for and it works! Thanks!

# June 17, 2011 3:57 PM

pregnancysymptoms said:

Pregnancy Symptoms grpcfgftc lrnocccd i yzqqguuvn dpebvmlqr zgly jkv sw                                                                      

tquxvcwoo okxebz bcw garmettrb aqhcza mlk                                                                      

thmalbqup meopmm opr                                                                      

dwj gyooag oul ruw vzs xs cd s dp u                                                                      

<a href=pregnancysymptomssigns.net Symptoms</a>                                                                          

vx sh tumv vq td suewcigntwmr f v zfiiwaifjdoooh acdpnm vukj zl eo                                                                      

ub us vo mpidghcbwxpdyooxvzlngzkghcnwtzmgswmgcx

# August 6, 2011 10:14 PM

Ted said:

I had a similar problem and resorted to turning of HTTP keep-alive among the common response headers in IIS. Works for both IIS6 and IIS7.

# October 10, 2011 7:06 AM

Bilal said:

Checked out your Gateway IP, Same problem did hurt me also on inspection i found that i did't give my Gateway IP to my LAN Card.

# November 21, 2011 11:42 PM

Martijn Balink said:

After upgrading my IIS backend from Windows 2003/IIS6 to Windows 2008/IIS7 I suddenly got 502 errors. Thanks to this post I was able to sort out the issue, thanks a lot!!!

# December 8, 2011 5:03 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)