Push http header into cookie
<p>I'm trying to propagate an http header across proxies using a cookie from apache 2.4 to nginx.</p>

<p>Apache is only around to do kerberos authentication against Active Directory. Due to the overhead that the AD authentication adds to every get request, I want to limit the authentication. The idea is to set a cookie that expires after x time and only perform the auth through apache if the cookie doesn't exist. 
Furthermore, I want the remote_user from apache made available to nginx.</p>

<p>Nginx listens on port 80, and does an auth sub-request to apache on port 81 (same host)</p>

<p>I am able to set http headers in apache, but these get lost in nginx land.</p>

<p>I first tried reading the specific http header that I am interested in from nginx, but I can't see it once the request is transferred to nginx, although I can see them being set on the apache side.</p>

<p>My second idea was to push the header that I am interested in to a server cookie and then extract it in the nginx side, but the cookie value is always empty.</p>

<p>In the apache conf I have:</p>

<pre><code>RewriteRule .* - [E=PROXY_USER:%{LA-U:REMOTE_USER}] 
Header add X-Auth-User %{PROXY_USER}e 
</code></pre>

<p>I can see that header fine on the apache side, but nothing on the nginx side.</p>

<p>Trying to pump the data into a cookie in apache:</p>

<pre><code>RewriteCond %{LA-U:REMOTE_USER} (.*)
RewriteRule ^/ - [env=COOKIE1:%1]
RewriteRule .* - [CO=acaprox:tst=%{COOKIE1}e:.my-domain.com:300:/] [R=307,L]
</code></pre>

<p>The trouble with this approach is that the value of test is always empty.</p>

<p>I also tried reusing the environment variable that I can successfully push into the header, into the cookie, but it is also always empty:</p>

<pre><code> RewriteRule .* - [CO=cookietest:tst=%{ENV:PROXY_USER}:.my-domain.com:300:/] [R=307,L]
</code></pre>

<p>As is probably blatantly obvious, I don't have much experience in this space. </p>