Skip to content

Commit 540f2fd

Browse files
authored
Merge pull request #7840 from mszixie/patch-9
AB#3080: Docs 2024 review: Update troubleshoot-502-2-bad-gateway-error-in-cgi-apps.md
2 parents 009c550 + fc30487 commit 540f2fd

1 file changed

Lines changed: 9 additions & 73 deletions

File tree

Lines changed: 9 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
22
title: Troubleshoot HTTP 502.2 Bad Gateway error in CGI applications
33
description: Describes HTTP 502.2 Bad Gateway error in CGI applications and provides troubleshooting steps to resolve this issue.
4-
ms.date: 04/09/2012
4+
ms.date: 12/31/2024
55
ms.author: haiyingyu
66
author: HaiyingYu
77
ms.reviewer: johnhart
88
ms.custom: sap:Site Behavior and Performance\Runtime errors and exceptions, including HTTP 400 and 50x errors
99
---
1010
# Troubleshoot HTTP 502.2 Bad Gateway error in CGI applications
1111

12-
_Applies to:_   Internet Information Services 6.0, Internet Information Services 7.0
12+
_Applies to:_   Internet Information Services
1313

1414
This article describes HTTP 502.2 Bad Gateway error in Common Gateway Interface (CGI) applications and provides troubleshooting steps to resolve this issue.
1515

1616
## Symptom
1717

18-
You have a Web site that is hosted on Internet Information Services (IIS) 7.0. When you visit the Web site in a Web browser, you may receive an error message that resembles the following:
18+
You have a Web site that is hosted on Internet Information Services (IIS). When you visit the Web site in a Web browser, you might receive an error message that resembles the following one:
1919

2020
> Server Error in Application \<application name\>
2121
> HTTP Error 502.2 - Bad Gateway
@@ -24,13 +24,12 @@ You have a Web site that is hosted on Internet Information Services (IIS) 7.0. W
2424
2525
## Cause
2626

27-
This problem occurs because the CGI process terminates unexpectedly before the CGI process sends a response back to IIS 7.0.
27+
This problem occurs because the CGI process terminates unexpectedly before the CGI process sends a response back to IIS.
2828

2929
## Tools
3030

31-
- Tracing module on IIS 7.X
32-
- [Enterprise Tracing for Windows (ETW Tracing)](/windows-hardware/drivers/devtest/event-tracing-for-windows--etw-) on IIS 6.0
33-
- [Microsoft Network Monitor 3.4](https://www.microsoft.com/download/4865)
31+
- Tracing module on IIS
32+
- [Microsoft Network Monitor 3.4](https://www.microsoft.com/en-us/download/details.aspx?id=4865)
3433

3534
## Troubleshooting steps
3635

@@ -50,7 +49,7 @@ HTTP: Content-Type =text/html
5049
HTTP: Server =Microsoft-IIS/6.0
5150
HTTP: Date =Tue, 23 Aug 2005 20:25:47 GMT
5251
HTTP: Data: Number of data bytes remaining = 232 (0x00E8)
53-
00000: 00 11 BC 3E 62 3C 00 0F 1F 6C 1F E1 08 00 45 00 ..¼>b<...l.á..E.
52+
00000: 00 11 BC 3E 62 3C 00 0F 1F 6C 1F E1 08 00 45 00 ..%>b<...l.á..E.
5453
00010: 01 9A EF 40 40 00 80 06 00 00 D8 A2 10 5C 0A C8 .šï@@.&euro;...Ø¢.\.È
5554
00020: 04 15 00 50 55 B1 AA C6 89 52 E7 D6 85 01 50 18 ...PU±ªÆ‰RçÖ….P.
5655
00030: 09 2F F9 67 00 00 48 54 54 50 2F 31 2E 31 20 35 ./ùg..HTTP/1.1 5
@@ -81,69 +80,6 @@ HTTP: Data: Number of data bytes remaining = 232 (0x00E8)
8180

8281
Capture [FREB](troubleshoot-php-with-failed-request-tracing.md) log for the HTTP error message and locate which module is throwing this error message.
8382

84-
Troubleshoot the CGI process executable file to determine why the CGI process terminates unexpectedly. You may have to generate a memory dump file of the CGI process when the access violation occurs.
85-
86-
This problem occurs when the CGI application does exactly what the error suggests: inserts invalid data into the HTTP Header value(s) that is sends to IIS as part of its response. In IIS 6 with Windows 2003 SP1 installed, you can use ETW Tracing to see what the CGI is returning.
87-
88-
### Capture a Trace file using ETW Tracing
89-
90-
1. Copy the ETWSetup.zip file to the IIS6 Server.
91-
1. Extract it on the server.
92-
1. Open the folder from the command prompt.
93-
1. Enter _iis6trace-start.cmd_ to start the tracing.
94-
1. Reproduce the issue.
95-
1. Enter _iis6trace-stop.cmd_ to stop the tracing.
96-
1. At this point, you should have an _iistrace\_etl.etl_ file in that folder.
97-
1. Zip up that file and send it to Microsoft Support Engineer.
98-
1. Support engineer can help you convert ETL file into XML.
99-
1. Here is an example trace file from this sort of CGI problem:
100-
101-
The request to the CGI starts at line 391:
102-
103-
```xml
104-
<ROW>
105-
<EventNumber>391</EventNumber>
106-
<EventName>IISGeneral</EventName>
107-
<EventTypeName>GENERAL_REQUEST_START</EventTypeName>
108-
<Timestamp>2005-08-23 20:19:06</Timestamp>
109-
<UserData>ContextId={00000000-0000-0000-4c06-0060000000ef}|SiteId=1|AppPoolId=DefaultAppPool|ConnId=-1224979097571031481|RawConnId=0|RequestURL=http://siteaddress:80/cgi-bin/htmlos.exe/00182.3.055317239900014075|RequestVerb=POST</UserData>
110-
</ROW>
111-
```
112-
113-
The request is processed by IIS, you see it's for a CGI, and it's passed along to the CGI. The CGI starts its processing at line 405:
114-
115-
```xml
116-
<ROW>
117-
<EventNumber>405</EventNumber>
118-
<EventName>IISCGI</EventName>
119-
<EventTypeName>CGI_LAUNCH</EventTypeName>
120-
<Timestamp>2005-08-23 20:19:07</Timestamp>
121-
<UserData>ContextId={00000000-0000-0000-4c06-0060000000ef}|CommandLine="D:\Inetpub\cgi-bin\htmlos.exe" |ErrorCode=0x00000000|ProcessId=3136</UserData>
122-
</ROW>
123-
```
124-
125-
Line 441 shows the problem in the CGI:
83+
Troubleshoot the CGI process executable file to determine why the CGI process terminates unexpectedly. You might have to generate a memory dump file of the CGI process when the access violation occurs.
12684

127-
```xml
128-
<ROW>
129-
<EventNumber>441</EventNumber>
130-
<EventName>IISCGI</EventName>
131-
<EventTypeName>CGI_PREMATURE_TERMINATION</EventTypeName>
132-
<Timestamp>2005-08-23 20:25:47</Timestamp>
133-
<UserData>ContextId={00000000-0000-0000-4c06-0060000000ef}|Headers=</UserData>
134-
</ROW>
135-
```
136-
137-
For some reasons, the CGI application is ended prematurely. Notice the value of the headers entry. It's empty. This is why the error is sent to the client that the CGI is sending a bad set of headers. It is in fact sending an empty list of headers.
138-
139-
Line 446 shows the 502 that is sent to the client. It's actually a 502.2 (substatus of 2):
140-
141-
```xml
142-
<ROW>
143-
<EventNumber>446</EventNumber>
144-
<EventName>IISGeneral</EventName>
145-
<EventTypeName>GENERAL_REQUEST_END</EventTypeName>
146-
<Timestamp>2005-08-23 20:25:47</Timestamp>
147-
<UserData>ContextId={00000000-0000-0000-4c06-0060000000ef}|BytesSent=370|BytesReceived=105906875|HttpStatus=502|HttpSubStatus=2</UserData>
148-
</ROW>
149-
```
85+
This problem occurs when the CGI application does exactly what the error suggests, inserting invalid data into the HTTP header values that are sent to IIS as part of its response.

0 commit comments

Comments
 (0)