<div class="im">Hi All,<br><br>I&#39;m getting the &quot;zero length URI to proxy&quot; error from line 925 in ngx_http_proxy_module.c.<br><br>I&#39;m the guy using nginx as a forward proxy, using Igor&#39;s config suggestion from yesterday:<br>
<br>http <br>{<br>

     resolver 127.0.0.1; # do not forget to run named on localhost<br>

<br>

     server {<br>

         location / {<br>

             proxy_pass  http://$http_host$http_request_line;<br><div id=":9" class="ii gt">
         }<br>
     }<br>}<br><br>My understanding is that this is because $http_host$http_request_line is not getting evaluated on each request from the client, and instead just once upon some initialization cycle?<br><br>I&#39;ve tried adding a trailing &#39;/&#39; to the expression, to make it &quot;proxy_pass  http://$http_host$http_request_line/;&quot;, which solves the &quot;zero length URI to proxy&quot; issue, but doesn&#39;t really have the correct behavior. That is, all requests to nginx in the form of <a href="http://example.com/foo">example.com/foo</a> end up being proxied to a backend URL of <a href="http://example.com/">example.com/</a>.<br>
<br>So, my question is, what&#39;s the best way to get nginx to act as a forward proxy? Do I need to manually change the logic in ngx_http_proxy_module.c? If so, I was thinking I could take the URI from the r parameter in ngx_http_proxy_create_request and manually stuff it into ctx-&gt;vars.uri. Would this help, or what would put me on the right track?<br>
<br>Thanks,<br>Mark<br><br>PS. An easy way to test the config is to set Firefox&#39;s proxy preferences to use the nginx instance. If you&#39;re able to surf the web through nginx, then the config is correct. So far, I&#39;ve been unable to do this with the exception of the degenerate case mentioned above. (Where all &quot;<a href="http://example.com/foo">example.com/foo</a>&quot; requests get proxied to to &quot;<a href="http://example.com/">example.com/</a>&quot; on the backend)<br>
<br></div><br><br><br><br><br><br><br>On Thu, Sep 10, 2009 at 02:12:55AM -0700, Mark Preston wrote:<br>
<br>
&gt; Hi All,<br>
&gt;<br>
&gt; My understanding is that nginx cannot be used as a forward proxy out of the<br>
&gt; box. Is this correct?<br>
&gt;<br>
&gt; If so, my thinking is that by making some small modifications to<br>
&gt; ngx_http_proxy_module.c, it would be possible to have a nginx.conf file with<br>
&gt; &quot;proxy_pass asdf&quot;, where asdf ends up being ignored with the new surgical<br>
&gt; edits to ngx_http_proxy_module.c. Instead of doing the complex lookups to<br>
&gt; figure out the backend server, it would simply pull out the &quot;Host&quot; from the<br>
&gt; browser/client request being made, and use that as the appropriate URL to<br>
&gt; fetch.<br>
&gt;<br>
&gt; Would this work?<br>
&gt;<br>
&gt; (As a background, I currently have a squid + ICAP setup in transparent proxy<br>
&gt; mode, and it works fine for proof-of-concept, but falls over in terms of<br>
&gt; performance. As a result, I&#39;m trying to use nginx as a replacement. And with<br>
&gt; the http_sub module, I&#39;m thinking I don&#39;t even need ICAP, since we only add<br>
&gt; a small snippet after the HTML head section of every web page.)<br>
&gt;<br>
&gt; If there are better / easier ways of getting nginx to work as a forward<br>
&gt; proxy, please let me know, and I&#39;d be happy to contribute the edits back.<br>
&gt;<br>
&gt; Thanks!<br>
&gt; Mark<br>
&gt;<br>
&gt; PS. If the response is in Russian, that&#39;s cool too. I can read it just fine<br>
&gt; (and speak it), but my writing is rather poor. :-)<br>
<br>
</div>Although writing in Russian is more easy for me I answer in English,<br>
since this is English mailing list.<br>
<br>
You may try the following configuration:<br>
<br>
http {<br>
<br>
     resolver 127.0.0.1; # do not forget to run named on localhost<br>
<br>
     server {<br>
         location / {<br>
             proxy_pass  http://$http_host$request_<div id=":9" class="ii gt">line;<br>
             sub         ...<br>
         }<br>
     }<br>
<br>
However, I can not say that it will work without any issue.<br>
<font color="#888888"><br>
<br>
--<br>
Igor Sysoev<br>
<a href="http://sysoev.ru/en/" target="_blank">http://sysoev.ru/en/</a></font></div>