Score:0

Use the same environment variable for HOSTNAME and identifying the web request server used

us flag

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?

Gerard H. Pille avatar
in flag
There is a directive - PassEnv or something - which tells Apache which EV's may be used.
us flag
@GerardH.Pille Thanks for `PassEnv`. However, I see in https://serverfault.com/a/441141/240770 that `PassEnv` is unnecessary.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.