July 26, 2007
CGI Woes Under IIS 6
At my lab, we just consolidated some web servers and we ran into some problems with a CGI application for online surveys called Perseus SurveySolutions that stopped working. I think it’s version 5. We were getting a “CGI misbehaving” error which is a 502.2 in the log files. For IIS 5, in addition to the 502 generic error message I used to be able to see all output to stdout (and probably stderr) in my browser window. Unfortunately, IIS 6 does not allow the output to be displayed.
I had a hunch that the program was crashing and printing something other than a valid header such as “Content-type: text/html” (and two newlines). Unfortunately, the program ran just fine from the command line.
Luckily, after much searching I found mention online of an “nph-“ prefix that can be placed at the beginning of an executable CGI (.exe) that will allow all output to be sent to the browser (example: nph-foo.exe). The NPH is for “no parsing of headers” apparently. You’ll probably get a file download dialog when using this trick and the default file name to save will end with “.exe” the same as your CGI executable; however this is actually text (assuming your CGI only outputs text) so just change the extension when you save. Also, if you have web service extensions enabled then you will have to explicitly give permission to your “nph-.exe” so that it can be run by IIS.
Once I did this I got some informative errors that Perseus (which is compiled Perl) was trying to write to “C:\WINNT\Temp\pdk-IUSR_IMTCWWW” and was failing due to permissions. The problem was that IUSR is the restricted user that executes CGI and didn’t have permissions to write to its temp directory. I suspect this had something to do with an in-place OS upgrade or the copying of files from one server to another and that directory was a leftover from a previous install. In any case, just deleting the directory and letting it be recreated fixed the problem!
Here’s where MSFT’s limited documentation of “nph” resides:
Info about NPH in IIS 6 (dead link removed, see below)
And here’s an informative newsgroup post from a msft employee about configuring CGI executables in IIS 6.
Newsgroup Post about CGI under IIS 6
(2nd post by David Wang [Msft] is the one to read)
Finally, here is a program I didn’t use but sounds like it could be useful for debugging CGI. It’s basically a Lint program for CGI.
Dead links
- http_//support.microsoft.com/kb/q176113