On Sat, Mar 24, 2012 at 2:20 AM, Zed <zedlau@gmail.com> wrote:
> Hi there,
>
> I'm trying to turn nginx to a proxy program which can reserve proxy any
> website. Here is my configuration files:
>
> location ^~/proxy {
> set $target $arg_url;
> default_type text/html;
> proxy_redirect off;
> proxy_pass $arg_url;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> proxy_set_header Accept-Encoding "";
> proxy_set_header Cache-Control "no-cache";
> }
>
> when i access http://my.domain.name/proxy?url=http://www.baidu.com, it
> returns 502 bad gateway.
>
If I were you, I would look into nginx's error.log for any error
messages. I bet you're getting the following error there:
[error] 3454#0: *1 no resolver defined to resolve www.baidu.com, ...
It clearly indicates the cause of the problem: you did not define any
resolver in your nginx.conf. The fix is simple, just adding the
following line to your config file:
resolver 114.114.114.114;
Of course, you may want to use other DNS nameserver here instead of
the public DNS server 114.114.114.114 :)
Another place of improvement in your sample is to use ngx_set_misc
module's set_unescape_uri directive to process the value of the
$arg_url variable.
BTW, I don't see ngx_echo is used in your sample here. Your email
title is rather misleading and confusing.
Best,
-agentzh
P.S. I've cc'd the openresty mailing group so that other people can
see our discussions here.