Web Servers on Unix and Linux - Logfile for vhosts (mod_rewrite)

This is Interesting: Free IT Magazines  
Home > Archive > Web Servers on Unix and Linux > March 2004 > Logfile for vhosts (mod_rewrite)





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Logfile for vhosts (mod_rewrite)
Rudolf Potucek

2004-03-18, 2:04 pm

Hi!

I am running apache 1.3.29 (linux debian package) with a few virtual
hosts configured via the mod_rewrite (see below). I would like to get
access logs separated for the various virtual hosts, so I am writing a
custom log using:

LogFormat "%{HTTP_HOST}e %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combinedvhost
CustomLog logs/access_log_vhosts combinedvhost

Which should in theory add the requested host name in the logfile ...
however what I get is really odd:

cure.artiverse.net 136.159.82.168 - - [08/Mar/2004:12:36:16 -0700] "GET / HTTP/1
- 136.159.82.168 - - [08/Mar/2004:12:36:17 -0700] "GET /pics/tn-cure1.jpg HTTP/1
- 136.159.82.168 - - [08/Mar/2004:12:36:17 -0700] "GET /pics/tn-cure2.jpg HTTP/1

So apparently in the requests for the images from the webpage there is no
HTTP_HOST variable set ... yet the requests are served correctly so
apache knows from which virtual host (they are in separated directories)
to serve the request ... how should this be configured so I get the
requested hostname in ALL logfile lines?

Thanks,

Rudolf

mod_rewrite config in httpd.conf:

# enable the rewriting engine in the main server
RewriteEngine on

# This is a bit dangerous because we clobber directories
# that may be legit ...
#
# Set up proxying the 'real name' into the global filesystem
# as REAL.artiverse.net/rest/of/uri <- any.host/homepages/REAL/rest/of/uri
#
RewriteCond %{REQUEST_URI} ^/homepages/([^/]+)(.*)/?$
RewriteRule ^.*$ http://%1.artiverse.net%2 [P]

# define two maps: one for fixing the URL and one which defines
# the available virtual hosts with their corresponding
# DocumentRoot.
RewriteMap lowercase int:tolower
RewriteMap vhost txt:/etc/httpd/conf/vhost.map

# Now do the actual virtual host mapping
# via a huge and complicated single rule:
#
# 1. make sure we don't map for common locations
#RewriteCond %{REQUEST_URI} !^/commonurl1/.*
#RewriteCond %{REQUEST_URI} !^/commonurl2/.*
#
#RewriteCond %{REQUEST_URI} !^/commonurlN/.*
#
# 2. make sure we have a Host header, because
# currently our approach only supports
# virtual hosting through this header
#
# also make sure that we don't get fooled
# by silly clients sending the IP!
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$
#
# and make sure we do not clobber user access via ~
RewriteCond %{REQUEST_URI} !^/~
#
#
# 3. lowercase the hostname
RewriteCond ${lowercase:%{HTTP_HOST}|NONE} ^(.+)$
#
# 4. lookup this hostname in vhost.map and
# remember it only when it is a path
# (and not "NONE" from above)
RewriteCond ${vhost:%1} ^(/.*)$
#
# 5. finally we can map the URL to its docroot location
# and remember the virtual host for logging puposes
#
RewriteRule ^/(.*)$ %1/$1 [E=VHOST:${lowercase:%{HTTP_HOST}}]



--
A great many people think they are thinking when they are merely
rearranging their prejudices.
-- William James
Rudolf Potucek

2004-03-18, 2:04 pm

Oops ... the solution seems to be really simple (duh) ... use the
'{Host}i' instead of '{HTTP_HOST}e' in the customlog directive ...

Well, maybe this will help someone on deja ...

Rudolf

In comp.os.linux.setup Rudolf Potucek <potucek@acs1.acs.ucalgary.ca> wrote:
: Hi!

: I am running apache 1.3.29 (linux debian package) with a few virtual
: hosts configured via the mod_rewrite (see below). I would like to get
: access logs separated for the various virtual hosts, so I am writing a
: custom log using:

: LogFormat "%{HTTP_HOST}e %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combinedvhost
: CustomLog logs/access_log_vhosts combinedvhost

: Which should in theory add the requested host name in the logfile ...
: however what I get is really odd:

: cure.artiverse.net 136.159.82.168 - - [08/Mar/2004:12:36:16 -0700] "GET / HTTP/1
: - 136.159.82.168 - - [08/Mar/2004:12:36:17 -0700] "GET /pics/tn-cure1.jpg HTTP/1
: - 136.159.82.168 - - [08/Mar/2004:12:36:17 -0700] "GET /pics/tn-cure2.jpg HTTP/1

: So apparently in the requests for the images from the webpage there is no
: HTTP_HOST variable set ... yet the requests are served correctly so
: apache knows from which virtual host (they are in separated directories)
: to serve the request ... how should this be configured so I get the
: requested hostname in ALL logfile lines?

: Thanks,

: Rudolf

: mod_rewrite config in httpd.conf:

: # enable the rewriting engine in the main server
: RewriteEngine on
:
: # This is a bit dangerous because we clobber directories
: # that may be legit ...
: #
: # Set up proxying the 'real name' into the global filesystem
: # as REAL.artiverse.net/rest/of/uri <- any.host/homepages/REAL/rest/of/uri
: #
: RewriteCond %{REQUEST_URI} ^/homepages/([^/]+)(.*)/?$
: RewriteRule ^.*$ http://%1.artiverse.net%2 [P]
:
: # define two maps: one for fixing the URL and one which defines
: # the available virtual hosts with their corresponding
: # DocumentRoot.
: RewriteMap lowercase int:tolower
: RewriteMap vhost txt:/etc/httpd/conf/vhost.map
:
: # Now do the actual virtual host mapping
: # via a huge and complicated single rule:
: #
: # 1. make sure we don't map for common locations
: #RewriteCond %{REQUEST_URI} !^/commonurl1/.*
: #RewriteCond %{REQUEST_URI} !^/commonurl2/.*
: #
: #RewriteCond %{REQUEST_URI} !^/commonurlN/.*
: #
: # 2. make sure we have a Host header, because
: # currently our approach only supports
: # virtual hosting through this header
: #
: # also make sure that we don't get fooled
: # by silly clients sending the IP!
: RewriteCond %{HTTP_HOST} !^$
: RewriteCond %{HTTP_HOST} !^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$
: #
: # and make sure we do not clobber user access via ~
: RewriteCond %{REQUEST_URI} !^/~
: #
: #
: # 3. lowercase the hostname
: RewriteCond ${lowercase:%{HTTP_HOST}|NONE} ^(.+)$
: #
: # 4. lookup this hostname in vhost.map and
: # remember it only when it is a path
: # (and not "NONE" from above)
: RewriteCond ${vhost:%1} ^(/.*)$
: #
: # 5. finally we can map the URL to its docroot location
: # and remember the virtual host for logging puposes
: #
: RewriteRule ^/(.*)$ %1/$1 [E=VHOST:${lowercase:%{HTTP_HOST}}]



: --
: A great many people think they are thinking when they are merely
: rearranging their prejudices.
: -- William James

--
Archist:
I know you have a [tyrant] inside you, right inside that hairy head
of yours. And she orders you around just like the old tyrant did her
serfs. She says: "Do this!" and you do, and "Don't" and you don't.
Anarchist (smiling):
That's where she [the tyrant] belongs, inside my head.
Archist:
No. Better to have her in a palace. Then you could rebel against her.
-- from Ursula K. LeGuin, The Dispossessed
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com