Our environment has servers named like so:
prod-app-01
prod-app-02
test-app-01
test-app-02
I've used sudo hostnamectl set-hostname test-app-02
on each server (changing the name appropriately each time) to set the name that appears in the terminal. Now I'd like to use the same name in Apache to identify which server fulfilled the web request by looking in the HTTP headers.
Inside the Apache /etc/apache2/sites-enabled/000-default.conf
file I've put:
Header set X-Server: test-app-02
However, this requires me to make the same change in two places every time. Our machines are cloned, so retain the settings from one to the next. I'd like to be able to only use sudo hostnamectl set-hostname test-app-02
and have that change reflected in Apache too (after a restart probably), however, it seems that Apache has no access to that information.
I tried setting HOSTNAME
as an environment variable but I was unsuccessful at getting Apache to use it (Header set X-Server: "%{env:HOSTNAME}"
, Header set X-Server: "%{HOSTNAME}e"
, etc.), getting either X-Server:
or X-Server: (null)
in the headers each time. It also seems that other functions such as hostname
(which is available on the terminal) are unavailable in Apache .conf
files.
Is there any way to make this change in only one place and have it reflected in both places?