httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Hornberger <...@caltech.edu>
Subject [users@httpd] <Location>, Action and SetHandler
Date Wed, 22 Sep 2004 22:13:51 GMT
Hello,

I'm trying to experiment with using CGI scripts and <Location> directives
to set up Apache handlers and am running into what, to me, looks like a
strange bit of behavior. As far as I can tell, Apache "refuses" to use a
CGI script as a handler unless a regular file corresponding to the
location given in the <Location> directive exists.

Can anyone on the list shed any light on why this is -- or appears to be
-- the case, and (even better) suggest an alternate configuration
that'll get Apache working the way I had hoped it would?

Here's the relevant bit of Apache configuration (I've stored this in the
file /etc/httpd/conf.d/test-handler.conf):

  <VirtualHost 127.0.0.1:80>
  ServerName test-handler.example.org
  DocumentRoot /home/charlie/test-handler
  ScriptAlias /cgi-bin /home/charlie/test-handler/cgi-bin
  Action test-handler /cgi-bin/test-handler.cgi
  <Location />
    SetHandler test-handler
  </Location>
  <Location /static>
    SetHandler None
  </Location>
  <Location /cgi-bin>
    SetHandler None
  </Location>
  </VirtualHost>

I expected this to cause Apache to use /cgi-bin/test-handler.cgi to
handle any requests for URLs that do _not_ fall beneath /static or
/cgi-bin. But that's not what I'm seeing.

The only time I get the behavior I was looking for is when I send a
request for http://test-handler.example.org/. Then, the CGI script is
invoked, and I see a page saying simply:

  You asked for /!

which is what I'd expect. The CGI script test-handler.cgi, in case
you're interested, is this simple bit of Python code:

  #!/usr/bin/env python
  import os
  print "Content-Type: text/plain"
  print ""
  print "You asked for %s!" % os.environ.get ('REQUEST_URI')

But when I send a request for something else -- say, /foo -- I get a 404
error and the following message in my error log:

  [Wed Sep 22 14:11:51 2004] [error] [client 127.0.0.1] File does not
  exist: /home/charlie/test-handler/foo

What I'd expected, obviously, is a page saying "You asked for /foo!"

If I change the 6th line of the configuration snippet shown above from
<Location /> to <Location /foo>, the same thing happens ... until I do
this:

  % touch /home/charlie/test-handler/foo

Suddenly, the behavior I want -- all requests beneath the specified
location are instead passed off to my CGI script -- is the behavior I
get. When I send a request for /foo, I get a page saying 'You asked for
/foo!' When I ask for /foo/bar, I get a page saying 'You asked for
/foo/bar!' Beautiful.

But that's not what I want. What I want is for everything beneath / to
get passed off to my CGI script (with a few exceptions). And I'm a bit
astonished by the fact that this empty-file trick is necessary --
especially since the docs suggest using <Location /> as "an easy way to
apply a configuration to the entire server." Should I be so surprised,
or have I simply failed to find the right section of the manual?

Two more related, but perhaps unimportant, observations:

1) The file doesn't even have to be readable; I can do a quick little

  % chmod 0600 /home/charlie/test-handler/foo

and things keep right on working.

2) It _doesn't_ work if /home/charlie/test-handler/foo is a directory;
in that case, a request for /foo or /foo/ works (the former is
automatically redirected to the latter), and I get a page saying 'You
asked for /foo/!' But a request for /foo/bar fails; I get a 404 error in
response, and the following message in my error log:

  [Wed Sep 22 14:27:00 2004] [error] [client 127.0.0.1] File does not
  exist: /home/charlie/test-handler/foo/bar

I've only subscribed to the digest version of this mailing list, so
please CC me on any replies! (Oh, I almost forgot: I'm running
Apache/2.0.50 on Linux (Fedora Core release 1).)

Many thanks in advance,
Charlie

* If the alternate solution does _not_ involve rewrite rules, I'll be
twice as grateful. If it does, I'll be pretty grateful anyway :-).

-- 
Charles Hornberger
Caltech / Division of the Humanities & Social Sciences

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message