Forum: NGINX Using HttpMapModule with proxy_pass got 502

Posted by amozz (Guest)
on 2013-01-23 12:17
(Received via mailing list)
Hi everyone,

My project needs to route http request to different host with different
domain name. I deployed HttpMapModule and proxy_pass, and the related
nginx.conf segment is following:

http {
   map $http_host $backend_servers {
        app.example.com       localdomain1; #if changed to ip, it's ok
        default                       localdomain2;
   }

   server {
        listen              80;
        server_name    localhost;
        location /{
             proxy_pass http://$backend_servers;
        }
   .......
   }

When I send the requet uri as http://app.example.com, the result is 502
error. But if I changed the maping value as IP address not domain name, 
it
worked with no problem. And if I change the proxy_pass item directly to
http://localdomain1, it also worked as normal.

Does the proxy_pass + http_map_module not refer to DNS look? or is there 
any
other point wrong in the nginx.conf ?

Thanks for any suggestion.

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,235450,235450#msg-235450
Posted by Maxim Dounin (Guest)
on 2013-01-23 15:21
(Received via mailing list)
Hello!

On Wed, Jan 23, 2013 at 06:16:52AM -0500, amozz wrote:

>    }
> When I send the requet uri as http://app.example.com, the result is 502
> error. But if I changed the maping value as IP address not domain name, it
> worked with no problem. And if I change the proxy_pass item directly to
> http://localdomain1, it also worked as normal.
>
> Does the proxy_pass + http_map_module not refer to DNS look? or is there any
> other point wrong in the nginx.conf ?
>
> Thanks for any suggestion.

For dynamic name resolution of upstream servers to work, you have
to configure resolver, see http://nginx.org/r/resolver.

You may also start looking into error log if something goes wrong.
In this case it should have "no resolver defined" errors logged.

--
Maxim Dounin
http://nginx.com/support.html
Posted by amozz (Guest)
on 2013-01-24 08:06
(Received via mailing list)
Thank you Maxim.

I added the resolver, and it works now!

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,235450,235522#msg-235522
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.