Using URL instead of IP

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using URL instead of IP

wld75
Hi,

I intend to use nginx as load balancer for routing traffic to an application
running on two separate Openshift (kubernetes) clusters.
The app urls are -> app.dc1.example.com and app.dc2.example.com.
When I curl to these individually I get required page.
However, it seems, nginx resolves it into IP instead of treating it as mere
destinations.
See below my config.

Since the apps are running on Openshift, they do not have a specific
(public) IP address.
Ping for app.dc1.example.com (and for that matter app.dc2.example.com) will
give the IP of the machine where DNS service is running for that Openshift
cluster.

Is there a way to configure nginx to route the requests to the URLs without
trying to resolve it into IP addresses?

Thanks
Swati

---
upstream lbtest {
        server app.dc1.example.com ;
        server app.dc2.example.com ;
}

server {
    listen 9087;
    location / {
        proxy_set_header Host $host;
        proxy_pass http://lbtest;
    }
}
---

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281790,281790#msg-281790

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Using URL instead of IP

Maxim Dounin
Hello!

On Tue, Nov 06, 2018 at 12:44:47AM -0500, swati wrote:

> Hi,
>
> I intend to use nginx as load balancer for routing traffic to an application
> running on two separate Openshift (kubernetes) clusters.
> The app urls are -> app.dc1.example.com and app.dc2.example.com.
> When I curl to these individually I get required page.
> However, it seems, nginx resolves it into IP instead of treating it as mere
> destinations.
> See below my config.
>
> Since the apps are running on Openshift, they do not have a specific
> (public) IP address.
> Ping for app.dc1.example.com (and for that matter app.dc2.example.com) will
> give the IP of the machine where DNS service is running for that Openshift
> cluster.
>
> Is there a way to configure nginx to route the requests to the URLs without
> trying to resolve it into IP addresses?
>
> Thanks
> Swati
>
> ---
> upstream lbtest {
> server app.dc1.example.com ;
> server app.dc2.example.com ;
> }
>
> server {
>     listen 9087;
>     location / {
>         proxy_set_header Host $host;
> proxy_pass http://lbtest;
>     }
> }
> ---

With nginx-plus commercial version, you can use "server ...
resolve", which is specially designed for such use cases.  See
here for details:

http://nginx.org/en/docs/http/ngx_http_upstream_module.html#resolve

With vanilla nginx, you can instruct nginx to always re-resolve
names by using variables:

    set $backend app.dc1.example.com;
    proxy_pass $backend;

You won't be able to use an upstream block with multiple names
though.  See here for details:

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

Note that in both cases you'll have to define a resolver to use,
see here:

http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx