|
|
Question : Getting a hosts name or IP in an Apache environment variable
|
|
I'm in the process of setting up some Apache servers (Apache 2, RedHat linux) to act as a fallback when we do maintainence on an existing website. I've created a maintainence webpage and set up a Rewrite rule that redirects all URL's to that page. Our intention is to have our sites load balancer redirect to this Apache instance when maintainence is occuring. Since we have a number of redundant systems behind our load balancer this same Apache configuration will actually be running on multiple servers.
Part of our site is an application that responds to HTTP requests from customers, and part of the response is a series of custom HTTP headers that we include. When the site is down for maintainence I'm replicating those headers via the Header directive, but filling in static values for those headers. One of these headers is the IP address of the server that served the request. Since we have multiple servers behind a load balancer this helps to identify which one a given request actually came from. I'd like to have this header get properly set when we enable this maintainence mode, but I'm not having any luck getting Apache to display a hostname or IP address. I've tried the following in my httpd.conf:
PassEnv HOSTNAME Header set DBG-Server-IP %{HOSTNAME}e
The HOSTNAME environment variable is set. echo $HOSTNAME from the command line does return the hostname of the server. However when I restart Apache I get the following:
Starting httpd: [Fri Feb 10 13:39:00 2006] [warn] PassEnv variable HOSTNAME was undefined
And when I issue an HTTP request to this server the headerlooks like this:
DBG-Server-IP: (null)
I really don't want to hardcode the server IP in the httpd.conf file since we use the identical conf file across all the servers. How can I set this up so that it's set dynamically when Apache loads?
|
Answer : Getting a hosts name or IP in an Apache environment variable
|
|
PAQed with points (50) refunded
DarthMod Community Support Moderator
|
|
|
|
|