"zero length URI to proxy" in ngx_http_proxy_module.c (more forward proxy troubles)

Hi All,

I’m getting the “zero length URI to proxy” error from line 925 in
ngx_http_proxy_module.c.

I’m the guy using nginx as a forward proxy, using Igor’s config
suggestion
from yesterday:

http
{
resolver 127.0.0.1; # do not forget to run named on localhost

server {
    location / {
        proxy_pass  http://$http_host$http_request_line;
    }
}

}

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?

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 example.com/foo end up being proxied to
a
backend URL of example.com/.

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?

Thanks,
Mark

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 "
example.com/foo" requests get proxied to to “example.com/” on the
backend)

On Thu, Sep 10, 2009 at 02:12:55AM -0700, Mark P. wrote:

Hi All,

My understanding is that nginx cannot be used as a forward proxy out of
the
box. Is this correct?

If so, my thinking is that by making some small modifications to
ngx_http_proxy_module.c, it would be possible to have a nginx.conf file
with
“proxy_pass asdf”, where asdf ends up being ignored with the new surgical
edits to ngx_http_proxy_module.c. Instead of doing the complex lookups to
figure out the backend server, it would simply pull out the “Host” from
the
browser/client request being made, and use that as the appropriate URL to
fetch.

Would this work?

(As a background, I currently have a squid + ICAP setup in transparent
proxy
mode, and it works fine for proof-of-concept, but falls over in terms of
performance. As a result, I’m trying to use nginx as a replacement. And
with
the http_sub module, I’m thinking I don’t even need ICAP, since we only
add
a small snippet after the HTML head section of every web page.)

If there are better / easier ways of getting nginx to work as a forward
proxy, please let me know, and I’d be happy to contribute the edits back.

Thanks!
Mark

PS. If the response is in Russian, that’s cool too. I can read it just
fine
(and speak it), but my writing is rather poor. :slight_smile:

Although writing in Russian is more easy for me I answer in English,
since this is English mailing list.

You may try the following configuration:

http {

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

server {
    location / {
        proxy_pass  http://$http_host$request_line;
        sub         ...
    }
}

However, I can not say that it will work without any issue.

On Fri, Sep 11, 2009 at 03:48:26AM -0700, Mark P. wrote:

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

upon some initialization cycle?
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 example.com/foo end up being proxied to a
backend URL of example.com/.

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 "
example.com/foo" requests get proxied to to “example.com/” on the backend)

Sorry, I mistaked:

  •        proxy_pass  http://$http_host$http_request_line;
    
  •        proxy_pass  http://$http_host$request_line;