Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running an apache2 instance behind an nginx reverse-proxy, with nginx performing basic authentication and apache2 serving up Nagios cgi scripts.

I am able to send the authenticated user from nginx to apache (currently using X-Forwarded-User header set to $remote_user) - but I am struggling to get apache2 to recognize this header and set the REMOTE_USER env variable before it executed the CGI script.

I believe mod_rewrite might be able to do this, but all the examples I have seen relate to the reverse scenario, where apache2 is sending REMOTE_USER downstream to another backend server.

Is it even possible to set REMOTE_USER within apache to something outside the realm of apache's own mod_auth module?

share|improve this question
up vote 2 down vote accepted

You need Apache's mod_setenvif and SetEnvIf directives.


SetEnvIf X-Forwarded-User (.*) REMOTE_USER=$1

Requires Apache 2.0.51 or later. Docs here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.