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.

link|improve this question

80% accept rate
feedback

2 Answers

up vote 1 down vote accepted

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.

link|improve this answer
feedback

You need to pass an Environment Variable using mod_env:

PassEnv HOSTNAME
Header set X-MyHeader "%{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

link|improve this answer
mod_headers for Apache 1.3 doesn't seem to support the %-style variables – EvanK Sep 2 '09 at 18:55
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.