6

On my Debian machine (running the apache as packaged by Debian, package 2.4.7-1), every time apache restarts through apache2ctl restart or apache2ctl graceful, it forgets about my cgi-bin directory:

me@aram:~$ sudo apache2ctl graceful-stop me@aram:~$ sudo apache2ctl graceful httpd not running, trying to start me@aram:~$ curl -s http://localhost/cgi-bin/hello Hello world, from a cgi script. me@aram:~$ sudo apache2ctl graceful me@aram:~$ curl -s http://localhost/cgi-bin/hello <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>404 Not Found</title> </head><body> <h1>Not Found</h1> <p>The requested URL /cgi-bin/hello was not found on this server.</p> <hr> <address>Apache/2.4.7 (Debian) Server at localhost Port 80</address> </body></html> me@aram:~$ sudo apache2ctl graceful me@aram:~$ curl -s http://localhost/cgi-bin/hello Hello world, from a cgi script. me@aram:~$ sudo apache2ctl graceful; sudo apache2ctl graceful me@aram:~$ curl -s http://localhost/cgi-bin/hello Hello world, from a cgi script. me@aram:~$ sudo apache2ctl graceful me@aram:~$ curl -s http://localhost/cgi-bin/hello <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>404 Not Found</title> </head><body> <h1>Not Found</h1> <p>The requested URL /cgi-bin/hello was not found on this server.</p> <hr> <address>Apache/2.4.7 (Debian) Server at localhost Port 80</address> </body></html> me@aram:~$ sudo apache2ctl graceful me@aram:~$ curl -s http://localhost/cgi-bin/hello Hello world, from a cgi script. 

This is perfectly repeatable; if I stop the server completely and restart it, it's fine. After that, a restart (graceful or not) switches behaviors. Unfortunately, the regular logrotate job issues a graceful restart, so I need to make it so that Apache always knows about cgi-bin.

There's nothing in the access or error log to mark a "will know about cgi" restart from a "won't know about cgi" restart. If people comment with suggestions as to how to make the logs more verbose, I'll try that and update this.

I'm using the config that the Debian package comes with (so it's configured by symlinking a bunch of files in -enabled directories to existing files in -available directories). Here, for reference, are what my -enabled directories contain:

me@aram:/etc/apache2$ ls *-enabled conf-enabled: 000-local-routerblock.conf charset.conf javascript-common.conf other-vhosts-access-log.conf serve-cgi-bin.conf apache2-doc.conf dwww.conf localized-error-pages.conf security.conf mods-enabled: access_compat.load authn_core.load authz_host.load cgi.load dir.load filter.load mpm_prefork.load reqtimeout.load status.load alias.conf authn_file.load authz_user.load deflate.conf dnssd.conf mime.conf negotiation.conf setenvif.conf userdir.conf alias.load authz_core.load autoindex.conf deflate.load dnssd.load mime.load negotiation.load setenvif.load userdir.load auth_basic.load authz_groupfile.load autoindex.load dir.conf env.load mpm_prefork.conf reqtimeout.conf status.conf sites-enabled: 000-default.conf 

All of those, except for 000-local-routerblock.conf, are as shipped by Debian. I've verified that removing that config file fixes the issue, so I suspect it's some odd interaction between that file and the default serve-cgi-bin.conf file. Again, though, no evidence in the logs.

Contents of 000-local-routerblock.conf:

Redirect /router /cgi-bin/router <Location "/cgi-bin/router"> AuthUserFile /usr/lib/cgi-bin/routerblock/htpasswd AuthGroupFile /dev/null AuthName ByPassword AuthType Basic Require user router </Location> 

Contents of serve-cgi-bin.conf:

<IfModule mod_alias.c> <IfModule mod_cgi.c> Define ENABLE_USR_LIB_CGI_BIN </IfModule> <IfModule mod_cgid.c> Define ENABLE_USR_LIB_CGI_BIN </IfModule> <IfDefine ENABLE_USR_LIB_CGI_BIN> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Require all granted </Directory> </IfDefine> </IfModule> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet 

EDIT: I've solved this now, in terms of "I made it work". I have no idea why this works, and that it does almost certainly indicates a bug in this version of Apache. I'm leaving the bounty up for someone to answer as to what is/was going on.

In any case, the solution was not in any of the config. files I quoted. Remember, the rest of this configuration is exactly stock Debian, nothing custom about the configuration. The Debian /etc/apache2/apache2.conf includes the line:

LogLevel warn 

In the stock configuration, there are no other LogLevel statements, except for a commented out one in the file /etc/apache2/sites-available/000-default.conf. (that entire file is inside a <VirtualHost *:80> tag; it sets up DocumentRoot and the access log, but nothing else)

I was messing around with LogLevel settings trying to get more information in my logs when I stumbled across this: if I have a LogLevel statement inside that VirtualHost tag, it works. So now in addition to the LogLevel warn that's in the main apache config, I also have a LogLevel warn inside the <VirtualHost *:80> tag in 000-default.conf. This works. If I have extra time this weekend, I think I'll try to set up a virtual machine to reproduce this in as clean an environment as possible, and then file a Debian bug.

5
  • 1
    Given that you're on Debian, is there any difference when using the service or invoke-rc.d calls? Like server apache2 restart Commented Apr 6, 2014 at 0:04
  • @OliverSalzburg - only the difference you'd expect from knowing how service apache2 handles restart vs reload - since service apache2 restart actually does a shutdown then restart, CGI is always found. With service apache2 reload, I get the switching behavior. Commented Apr 6, 2014 at 9:24
  • It does sound like a bug that it toggles between these two modes when reloading with the exact same configuration. Commented Apr 6, 2014 at 10:13
  • 4
    Now reported as a bug to Debian: bugs.debian.org/743860 Commented Apr 7, 2014 at 19:39
  • I wrote a hard apache restarter script for the task: first it tried a graceful stop, then waited some seconds, and then killed what remained, waited some seconds and made a start. It wasn't really beautiful, but worked... Commented Apr 20, 2015 at 17:47

1 Answer 1

1

Based on the comments and link to a bug report above, this does appear to have been a valid bug that has been recently resolved; from https://bugs.debian.org/743860 :

From: Jean-Michel Vourgère
To: [email protected]
Subject: Re: apache2: Apache forgets about /cgi-bin on restart
Date: Mon, 08 Jun 2015 00:12:12 +0000

Source: apache2 Source-Version: 2.4.10-1

Hello

We believe that the bug you reported is fixed.

Thank you for reporting the bug, which will now be closed. If you have further comments please address them to [email protected], and a maintainer will reopen the bug report if appropriate.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.