共用方式為


Unable to browse a CGI application scripted in PERL: 500-Internal Server Error

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

Error Summary

HTTP Error 500.0 - Internal Server Error

The page cannot be displayed because an internal server error has occurred.

Detailed Error Information

Module

CgiModule

Notification

ExecuteRequestHandler

Handler

CGI

Error Code

0x800700c1

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: https://learn.iis.net/page.aspx/266/troubleshooting-failed-requests-using-tracing-in-iis

r

MODULE_SET_RESPONSE_ERROR_STATUS Warning

ModuleName="CgiModule", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="%1 is not a valid Win32 application.

 (0x800700c1)", ConfigExceptionInfo=""

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: https://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:

<isapiCgiRestriction notListedIsapiisAllowed="false" notListedCgisAllowed="false"> <add path="C:\inetpub\wwwroot\CGI\Test.cgi" allowed="true" description="TEST-CGI" /> </isapiCgiRestriction>

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: https://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.

Server Error in Application "DEFAULT WEB SITE/CGI"

Internet Information Services 7.5

Error Summary

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 "".

Detailed Error Information

Module

CgiModule

Notification

ExecuteRequestHandler

Handler

CGI

Error Code

0x00000000

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:

<system.webServer>    <handlers accessPolicy="Read, Execute, Script">       <add name="CGI" path="*.cgi" verb="*" modules="CgiModule" scriptProcessor="C:\Perl64\bin\perl.exe “%s” %s" resourceType="Either" requireAccess="Script" />    </handlers> </system.webServer>
Note: While adding the script map entry you would be prompted to add a entry in ISAPI and CGI restriction list. When prompted click on the “YES” button. 2651170

More Information:

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:

Server Error in Application "DEFAULT WEB SITE/CGI"

Internet Information Services 7.5

Error Summary

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 "Can't open perl script "C": No such file or directory ".

Detailed Error Information

Module

CgiModule

Notification

ExecuteRequestHandler

Handler

CGI

Error Code

0x00000002

You could also refer the following link on how to configure ActivePerl for IIS: https://www.activestate.com/blog/2010/06/setting-iis-activeperl

https://docs.activestate.com/activeperl/5.10/bin/ap-iis-config.html

Comments

  • Anonymous
    June 17, 2013
    The comment has been removed

  • Anonymous
    February 12, 2014
    I had an issue with CGI scripts not working on a new server,  I thank you so much for helping me get past them after hours of struggling with figuring it out.

  • Anonymous
    February 12, 2014
    @Bryan - Good to know this helped you :)