Skip to content

Instantly share code, notes, and snippets.

@ollyg
Last active December 19, 2023 19:09
Show Gist options
  • Save ollyg/5782078 to your computer and use it in GitHub Desktop.
Save ollyg/5782078 to your computer and use it in GitHub Desktop.
Setting X-REMOTE_USER in Apache proxied request
RequestHeader unset X-REMOTE_USER
RequestHeader set X-REMOTE_USER "%{REMOTE_USER}e" env=REMOTE_USER
# see http://httpd.apache.org/docs/current/mod/mod_headers.html#header
@maxb
Copy link

maxb commented Dec 19, 2023

The example above is incorrect, because it assumes REMOTE_USER is an environment variable. It is not (unless some non-standard additional configuration has additionally defined such a variable).

Instead it is a special property of the request, best accessed via expr= functionality (2.4.10 or later required)

RequestHeader set X-Remote-User "expr=%{REMOTE_USER}" "expr=-n %{REMOTE_USER}"

@ollyg
Copy link
Author

ollyg commented Dec 19, 2023

Specifically when Apache is running a reverse proxy together with local authentication within Apache (for example mod_webauth), there is a legitimate use case for the config above to pass the username set by authentication through to the proxied app. I can imagine without this context it would not seem a very useful configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment