Summary
Apache has the ability to return its Hostname via the X-Served-By header. When troubleshooting nodes behind a Load Balancer, this can help localize a problematic node. This guide will demonstrate how to include the X-Served-By header in Apache
Configuration
Export the server hostname to apache
- CentOS File: /etc/sysconfig/httpd
- Ubuntu File: /etc/apache2/envvars
Add the following to Apache’s environment configuration file:
export HOSTNAME=$(hostname)
Add the X-Served-By header
1.Add the following to a VirtualHost or any other Apache configuration file:
<IfModule mod_headers.c>
PassEnv HOSTNAME
Header set X-Served-By “%{HOSTNAME}e”
</IfModule>
Dependency warning
The above lines require that mod_headers is enabled. Make sure that this module is enabled if you encounter any issues
Restart Apache:
# service httpd restart
Test it out:
$ curl -I localhost
HTTP/1.1 200 OK
Date: Sat, 14 Apr 2012 05:27:03 GMT
Server: Apache
Last-Modified: Sat, 14 Apr 2012 05:25:39 GMT
ETag: “5a2ae-0-4bd9cd1c8fac0”
Accept-Ranges: bytes
X-Served-By: web01
Content-Type: text/html; charset=UTF-8