<div class="im">Hi All,<br><br>I'm getting the "zero length URI to proxy" error from line 925 in ngx_http_proxy_module.c.<br><br>I'm the guy using nginx as a forward proxy, using Igor'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've tried adding a trailing '/' to the expression, to make it "proxy_pass http://$http_host$http_request_line/;", which solves the "zero length URI to proxy" issue, but doesn'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'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->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's proxy preferences to use the nginx instance. If you're able to surf the web through nginx, then the config is correct. So far, I've been unable to do this with the exception of the degenerate case mentioned above. (Where all "<a href="http://example.com/foo">example.com/foo</a>" requests get proxied to to "<a href="http://example.com/">example.com/</a>" 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>
> Hi All,<br>
><br>
> My understanding is that nginx cannot be used as a forward proxy out of the<br>
> box. Is this correct?<br>
><br>
> If so, my thinking is that by making some small modifications to<br>
> ngx_http_proxy_module.c, it would be possible to have a nginx.conf file with<br>
> "proxy_pass asdf", where asdf ends up being ignored with the new surgical<br>
> edits to ngx_http_proxy_module.c. Instead of doing the complex lookups to<br>
> figure out the backend server, it would simply pull out the "Host" from the<br>
> browser/client request being made, and use that as the appropriate URL to<br>
> fetch.<br>
><br>
> Would this work?<br>
><br>
> (As a background, I currently have a squid + ICAP setup in transparent proxy<br>
> mode, and it works fine for proof-of-concept, but falls over in terms of<br>
> performance. As a result, I'm trying to use nginx as a replacement. And with<br>
> the http_sub module, I'm thinking I don't even need ICAP, since we only add<br>
> a small snippet after the HTML head section of every web page.)<br>
><br>
> If there are better / easier ways of getting nginx to work as a forward<br>
> proxy, please let me know, and I'd be happy to contribute the edits back.<br>
><br>
> Thanks!<br>
> Mark<br>
><br>
> PS. If the response is in Russian, that's cool too. I can read it just fine<br>
> (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>