Enabling Apache basic auth to work with proxied apps

Recently, I needed to make some changes to a Sinatra based app to support multiple users. I already had basic auth set up, but it wasn't being passed to the unicorn-based Sinatra app that was being proxied behind Apache. Here's what I did.

First, make sure that you have the headers module set up. Then, in your ProxyPass section, add the following:

RewriteEngine On
RewriteCond %{REMOTE_USER} (.+)
RewriteRule . - [E=RU:%1]
RequestHeader set REMOTE_USER %{RU}e

Then in your Sinatra app, you just need to fetch the username from request['HTTP_REMOTE_USER']

Problem solved.