On Jan 20, 2008 11:34 PM, Eden Li &lt;<a href="mailto:eden@mojiti.com">eden@mojiti.com</a>&gt; wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
if i understand correctly, you need to terminate the &quot;local backend&quot;<br>request at nginx before passing back data to the client.<br><br>&nbsp;1. end user asks for protected content from nginx<br>&nbsp;2. nginx asks for auth token from &quot;local backend&quot;
<br>&nbsp;3. nginx proxies the rest of the connection from (1) attaching the<br>auth token from (2) to the request.<br><br>you probably need more than nginx for this. &nbsp; you might be able to<br>shove step (2) into an embedded perl module, but most likely you&#39;ll
<br>need to do this in an fcgi handler or somesuch.<br><div><div></div><div class="Wj3C7c"></div></div></blockquote><div><br>Eden, yes, you have it correct.<br><br>The fundamental problem here is around passing the auth token header to the remote proxy.
<br>It appears that when using X-Accel-Redirect, nginx will not pass headers generated by the backend through to the redirect target.<br><br>Igor, do I have this right?<br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div class="Wj3C7c"><br>On Jan 21, 2008 10:54 AM, Brendan Schwartz &lt;<a href="mailto:bschwartz@tropist.com">bschwartz@tropist.com</a>&gt; wrote:<br>&gt;<br>&gt; On Jan 20, 2008 4:07 PM, Manlio Perillo &lt;<a href="mailto:manlio_perillo@libero.it">
manlio_perillo@libero.it</a>&gt; wrote:<br>&gt; &gt; Brendan Schwartz ha scritto:<br>&gt; &gt;<br>&gt; &gt; &gt; On Dec 29, 2007 5:48 PM, Evan Miller &lt;<a href="mailto:emmiller@gmail.com">emmiller@gmail.com</a>&gt; wrote:
<br>&gt; &gt; &gt;&gt; Brendan Schwartz wrote:<br>&gt; &gt; &gt;&gt;&gt; Is there a way to get Nginx to send nonstandard response headers (e.g.<br>&gt; &gt; &gt;&gt;&gt; &quot;User-Header&quot;); it looks like they&#39;re being filtered.
<br>&gt; &gt; &gt;&gt;&gt;<br>&gt; &gt; &gt;&gt;&gt; Thanks,<br>&gt; &gt; &gt;&gt;&gt; Brendan<br>&gt; &gt; &gt;&gt; Check out the proxy_pass_header directive.<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;&gt; <a href="http://wiki.codemongers.com/NginxHttpProxyModule#proxy_pass_header" target="_blank">
http://wiki.codemongers.com/NginxHttpProxyModule#proxy_pass_header</a><br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;&gt; Evan<br>&gt; &gt; &gt;&gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; This doesn&#39;t seem to be working for me. Here&#39;s an example of what I&#39;m
<br>&gt; &gt; &gt; trying to accomplish:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; I have a local backend that returns a response that includes<br>&gt; &gt; &gt; X-Accel-Redirect, Authorization, and Some-Other-Header headers among
<br>&gt; &gt; &gt; others.<br>&gt; &gt; &gt; And I have a /remote-proxy location whose job it is to proxy the<br>&gt; &gt; &gt; X-Accel-Redirect to a remote server.<br>&gt; &gt; &gt; See example configuration below.<br>&gt; &gt; &gt;
<br>&gt; &gt; &gt; I would like the proxy-pass request to the remote server to include<br>&gt; &gt; &gt; the Authorization and Some-Other-Header headers that were returned in<br>&gt; &gt; &gt; the local backend upstream response.
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; I&#39;ve tried to use the proxy_pass_header directive, but haven&#39;t had<br>&gt; &gt; &gt; much luck as my &quot;custom&quot; headers aren&#39;t being passed to the remote<br>&gt; &gt; &gt; proxy server.
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Am I using these directives correctly? Is what I&#39;m trying to do impossible?<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Thanks,<br>&gt; &gt; &gt; Brendan<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;
<br>&gt; &gt; &gt; ---------------------------------------------------------------------<br>&gt; &gt; &gt; server {<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &nbsp; # standard config ...<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &nbsp; &nbsp; location /remote-proxy/ {
<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; internal;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_set_header &nbsp;X-Real-IP &nbsp;$remote_addr;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; # needed for HTTPS<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_set_header &nbsp;X-Forwarded-For $proxy_add_x_forwarded_for;
<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_set_header Host <a href="http://remote.server.com" target="_blank">remote.server.com</a>;<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_redirect false;<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_max_temp_file_size 0;<br>
&gt; &gt; &gt;<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; rewrite ^/remote-proxy/(.*)$ /$1 break;<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_pass <a href="https://remote.server.com" target="_blank">https://remote.server.com</a>;<br>&gt; &gt;<br>&gt; &gt; Here, instead of using a rewrite, try with
<br>&gt; &gt;<br>&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;proxy_pass <a href="https://remote.server.com/remote-proxy/" target="_blank">https://remote.server.com/remote-proxy/</a><br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; &gt; &nbsp; &nbsp; }<br>&gt; &gt; &gt;
<br>&gt; &gt; &gt; &nbsp; &nbsp; location / {<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_set_header &nbsp;X-Real-IP &nbsp;$remote_addr;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; # needed for HTTPS<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_set_header &nbsp;X-Forwarded-For $proxy_add_x_forwarded_for;
<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_set_header Host $http_host;<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_redirect false;<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_max_temp_file_size 0;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_pass_header Authorization;
<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_pass_header Some-Other-Header;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &nbsp; &nbsp; &nbsp; proxy_pass <a href="http://local_backend_upstream" target="_blank">http://local_backend_upstream</a>;<br>&gt; &gt; &gt;
<br>&gt; &gt; &gt; &nbsp; &nbsp;}<br>&gt; &gt; &gt; }<br>&gt; &gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; I&#39;m not sure to understand what you are trying to do.<br>&gt; &gt; But try with:<br>&gt; &gt;<br>&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; set $authorization upstream_http_authorization;
<br>&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; set $some_other upstream_http_some_other_header;<br>&gt; &gt;<br>&gt; &gt; in the / location<br>&gt; &gt;<br>&gt; &gt; and:<br>&gt; &gt;<br>&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header Authorization $authorization;
<br>&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; proxy_set_header Some-Other-Header $some_other;<br>&gt; &gt;<br>&gt; &gt; in the remote-proxy location<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; However I&#39;m rather sure that this will not work :).<br>
&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; Manlio Perillo<br>&gt; &gt;<br>&gt; &gt;<br>&gt;<br>&gt; Manlio,<br>&gt;<br>&gt; Unfortunately this doesn&#39;t seem to work. &quot;set $authorization<br>&gt; upstream_http_authorization;&quot; sets the $authorization variable to the
<br>&gt; string &quot;upstream_http_authorization&quot;. If I change the line to &quot;set<br>&gt; $authorization $upstream_http_authorization;&quot;, it doesn&#39;t work either.<br>&gt; I think that&#39;s because in Location / the Authorization header isn&#39;t
<br>&gt; set yet -- it&#39;s set by the local backend.<br>&gt;<br>&gt; I&#39;m trying to use nginx as a proxy for a remote server. But in order<br>&gt; to access the content on the remote server, I need to pass an<br>&gt; Authorization header to it. The local backend is able to produce valid
<br>&gt; authorization tokens.<br>&gt;<br>&gt; So here&#39;s what I want to happen: the local backend produces an<br>&gt; Authorization header which is then passed to the remote server<br>&gt; backend. The remote server accepts the authorized request and returns
<br>&gt; the protect content to nginx which passes it on to the end user.<br>&gt;<br>&gt; Does this make sense?<br>&gt;<br>&gt; Thanks,<br>&gt; Brendan<br>&gt;<br>&gt;<br><br></div></div></blockquote></div>