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.
You need to pass an Environment Variable using mod_env:
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
Untested, but how about passing the line in via the init (or other startup) script? Something like:
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.I had this same issue and I solved it using the
PassEnv
Apache config directive which imports an environment variable from the system shell into the Apache config environment.Fortunately for me I found that HOSTNAME was already set in my system shell environment. You can check what's available in your shell environment using
printenv
on the command line.So as long as the HOSTNAME environment variable is set differently on each server you can still have identical Apache configurations for all and each will report it's unique identity in the header.
I tested this on CentOS 7 with Apache 2.4. I tried to look up the Apache docs for V1.3 to see if the same directives were available in that version, but it seems that docs before Version 2.2 are no longer available at apache.org.
With Apache 2.4.9 on Ubuntu 18.04, this worked for me
What actually ended up working for me and my proxy setup though was to use ProxyVia instead