lighttpd: can not run CGI files ('404' error messages for CGI files accessed locally)

Bug #292347 reported by Deapesh
20
This bug affects 2 people
Affects Status Importance Assigned to Milestone
lighttpd (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

Binary package hint: lighttpd

I am running lighttpd 1.4.19 on Ubuntu 8.04.1.

I have been trying to get CGI scripts running on the server. These scripts will be accessed only from the localhost (and I am not using port 80).

After the following steps:
* enable mod_cgi
* create cgi script cgi.pl in /usr/lib/cgi-bin/ (with 755 permissions)
trying to access the file via the URL http://127.0.0.1:8888/cgi-bin/cgi.pl results in a 404 error

After a lot of head-banging and frustration I think the reason for this error is the second line in the below code excerpt from 10-cgi.conf:

$HTTP["remoteip"] == "127.0.0.1" {
        alias.url += ( "/cgi-bin/" => "/usr/lib/cgi-bin/" ) #--->CAUSE FOR THE ERROR!!
 $HTTP["url"] =~ "^/cgi-bin/" {
  cgi.assign = ( ".pl" => "/usr/bin/perl" )
 }
}

I then found this issue reported within a Debian bug discussion:http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=345554#53

As mentioned by Vedran Furač, the second alias is superfluous within the 10-cgi.conf file.

Relevant code excerpt from the 10-cgi.conf file:

$HTTP["remoteip"] == "127.0.0.1" {
        alias.url += ( "/cgi-bin/" => "/usr/lib/cgi-bin/" ) #--->CAUSE FOR THE ERROR!!
 $HTTP["url"] =~ "^/cgi-bin/" {
  cgi.assign = ( ".pl" => "/usr/bin/perl" )
 }
}
The second line results in '404' errors, when trying to execute a CGI file. Commenting it out, solves the problem.

With the default 10-cgi.conf file, running /usr/sbin/lighttpd -tp -f lighttpd.conf
results in this relevant snippet:

    $HTTP["remoteip"] == "127.0.0.1" {
        # block 1
        alias.url = (
            "/cgi-bin/" => "/usr/lib/cgi-bin/, /usr/lib/cgi-bin/",
            "/doc/" => "/usr/share/doc/",
            "/images/" => "/usr/share/images/",
            # 3
        )

One can notice the superfluous paths. The relevant error message from the lighttpd error log is:

2008-11-01 15:26:40: (response.c.212) -- splitting Request-URI
2008-11-01 15:26:40: (response.c.213) Request-URI : /cgi-bin/cgi.pl
2008-11-01 15:26:40: (response.c.214) URI-scheme : http
2008-11-01 15:26:40: (response.c.215) URI-authority: 127.0.0.1:8888
2008-11-01 15:26:40: (response.c.216) URI-path : /cgi-bin/cgi.pl
2008-11-01 15:26:40: (response.c.217) URI-query :
2008-11-01 15:26:40: (response.c.267) -- sanatising URI
2008-11-01 15:26:40: (response.c.268) URI-path : /cgi-bin/cgi.pl
2008-11-01 15:26:40: (mod_access.c.135) -- mod_access_uri_handler called
2008-11-01 15:26:40: (response.c.382) -- before doc_root
2008-11-01 15:26:40: (response.c.383) Doc-Root : /var/www/
2008-11-01 15:26:40: (response.c.384) Rel-Path : /cgi-bin/cgi.pl
2008-11-01 15:26:40: (response.c.385) Path :
2008-11-01 15:26:40: (response.c.433) -- after doc_root
2008-11-01 15:26:40: (response.c.434) Doc-Root : /var/www/
2008-11-01 15:26:40: (response.c.435) Rel-Path : /cgi-bin/cgi.pl
2008-11-01 15:26:40: (response.c.436) Path : /var/www/cgi-bin/cgi.pl
2008-11-01 15:26:40: (response.c.453) -- logical -> physical
2008-11-01 15:26:40: (response.c.454) Doc-Root : /var/www/
2008-11-01 15:26:40: (response.c.455) Rel-Path : /cgi-bin/cgi.pl
2008-11-01 15:26:40: (response.c.456) Path : /usr/lib/cgi-bin/, /usr/lib/cgi-bin/cgi.pl
2008-11-01 15:26:40: (response.c.473) -- handling physical path
2008-11-01 15:26:40: (response.c.474) Path : /usr/lib/cgi-bin/, /usr/lib/cgi-bin/cgi.pl
2008-11-01 15:26:40: (response.c.530) -- file not found
2008-11-01 15:26:40: (response.c.531) Path : /usr/lib/cgi-bin/, /usr/lib/cgi-bin/cgi.pl

I guess the second alias line needs to be deleted.

thanks,
Deapesh.

Revision history for this message
Deapesh (deapesh) wrote :

Seems like Ubuntu bug Bug #179484 is also due to this issue.

Revision history for this message
Deapesh (deapesh) wrote :

Hmm.. this bug report could be merged with Bug #179484 and the title of that bug report changed to appropriately describe the error.

Revision history for this message
Ryan Kavanagh (ryanakca) wrote :

I can confirm this

Changed in lighttpd:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
rameshnerella (nerellaramesh) wrote :

i got the same problem..this should be a bug..
thanks for the info Deapesh..
deleting / modifying some lines worked for me.. here is my 10-cgi.conf file
server.modules += ( "mod_cgi" )

$HTTP["remoteip"] == "127.0.0.1" {
 alias.url = ( "/cgi-bin/" => "/usr/lib/cgi-bin/" )
 $HTTP["url"] =~ "^/cgi-bin/" {
  cgi.assign = ( "" => "" )
 }
}

$HTTP["url"] =~ "^/cgi-bin/" {
 cgi.assign = ( "" => "" )
}

cgi.assign = (
 ".pl" => "/usr/bin/perl",
 ".php" => "/usr/bin/php-cgi",
 ".py" => "/usr/bin/python",
)

Revision history for this message
Deapesh (deapesh) wrote :

Has this bug been resolved?

Revision history for this message
sanitycheck (gcompton) wrote :

CGI programs stopped working after upgrade of working 8.10 server to 9.04. Subsequent upgrade to 9.10 did not fix. Complete fresh 9.10 server install on server previously upgraded will still not run CGI programs.

Can reproduce problem on a second vanilla 64-bit test install of Kubuntu 9.10 (in VMWare Workstation). Lighttpd installed using aptitude, mod_cgi added to stock lighttpd.conf. "Sudo lighty-enable-mod cgi" runs successfully. Simple known-good test.cgi application copied to /usr/lib/cgi-bin/. Permissions of test.cgi set wide open for testing. Try to access http://localhost/cgi-bin/test.cgi on local machine is successful using Firefox. Access attempt using remote machine by address (e.g. http://192.168.20.170/cgi-bin/test.cgi) gives "404 - Not Found."

Related problem: Trying to set server.bind to anything other than localhost in lighttpd.conf fails with error "Address family for hostname not supported." This problem is not present on a similarly-configured 8.04 server; there I can change server.bind to the IP4 address with no errors on service restart.

Revision history for this message
sanitycheck (gcompton) wrote :

Under "Related Problem" above I meant to say that trying to set the server.bind option at all fails with the error I listed. The configuration that works has the server.bind option commented out (the commented-out example is localhost), which is the default configuration.

In that configuration the CGI scripts will run on the local machine, but not from a remote machine. The default index page, however, will display correctly on both the local and a remote machine.

Revision history for this message
gstrauss (gstrauss) wrote :
Changed in lighttpd (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.