Recently I had to troubleshoot a issue where the users were reporting the following error while browsing the site hosted on IIS.
Server Error in Application "DEFAULT WEB SITE/CGI"
Internet Information Services 7.5
HTTP Error 500.0 - Internal Server Error
The page cannot be displayed because an internal server error has occurred.
Detailed Error Information
I captured a FREB trace to determine the entry point of failure. FREB always come in handy during troubleshooting such issues.
Please refer the following link on how to configure FREB: http://learn.iis.net/page.aspx/266/troubleshooting-failed-requests-using-tracing-in-iis
ModuleName="CgiModule", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="%1 is not a valid Win32 application.
Looking at the above error, I tried changing the application pool bitness, but that didn’t help. I was still stuck with the same error.
IIS was configured as per the following article on IIS.NET: http://www.iis.net/ConfigReference/system.webServer/cgi
We also had an ISAPI and CGI restriction entry for the path where the page was stored on disk.
For e.g: If the page is stored under location: C:\inetpub\wwwroot\CGI\test.cgi, then there would be a entry in applicationhost.config under <isapiCgiRestriction> as shown below:
So the problem was that the page was scripted using PERL. So the above article cannot be used as a reference. Instead we need to download PERL and configure it on the server.
So we downloaded and installed Perl from the below link: http://www.activestate.com/activeperl/downloads
The default installation location is: C:\Perl64. Once installed, we added the handler mapping for .cgi and pointed it to “C:\Perl64\bin\perl.exe”.
Assuming the issue was resolved, I browsed the page again only to be greeted with a different error message.
HTTP Error 502.2 - Bad Gateway
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "".
After researching on this error I found my answer. The handler mapping should be set to: “C:\Perl64\bin\perl.exe "%s" %s”.
Look at the example given below:
In the above handler mapping the parameters “%s” %s are case sensitive; they must be in lower-case. If there is a capitalization mismatch. Lets say if they are set to “%S” %S the following error would be seen:
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "Can't open perl script "C": No such file or directory ".
You could also refer the following link on how to configure ActivePerl for IIS: http://www.activestate.com/blog/2010/06/setting-iis-activeperl