Sending machine hostname as a header in Apache

I have a group of linux apache 1.3 servers behind a load balancer, and I want to be able to, at a glance, determine which server I'm hitting. The load balancer is severely limited in its monitoring capabilities, so what I'd like to do is configure apache to send an additional header indicating the machine's hostname.

I know I could just hard-code a header into the httpd.conf with the hostname:

Header set X-Which-Host-Am-I 'host1'

However, all the servers in question are mirrored with rsync, including the configs, so hard-coding the hostnames is out. Is there a way I can call the hostname command and dump it into a header?

Clarification: Since multiple virtual hosts live on these servers, I want the physical machine's hostname, not the domain name in the request.


Solution 1:

Untested, but how about passing the line in via the init (or other startup) script? Something like:

/path/to/httpd -c "Header set X-Hostname $HOSTNAME"

If you're using a RH-flavour distro you might be able to squeeze this into /etc/sysconfig/httpd or similar to avoid editing the init script.

Solution 2:

You need to pass an Environment Variable using mod_env:

PassEnv HOSTNAME
Header set X-Hostname "%{HOSTNAME}e"

You can set the value of HOSTNAME through the envvars file (mine is /etc/apache2/envvars)

Also, if you're using PHP you can use environment variables