Dynamic different IPs against Single public URL

44 views
Skip to first unread message

Muby M

unread,
Aug 20, 2017, 11:43:37 AM8/20/17
to openresty-en
Hi All

The requirement is to dynamically transfer the enterprise customers (via single public URL ) to their respective instance of the application hosted on different IP network.
For example  Customer_1 has an instance of application App_1 hosted on IP address IP_1, and same way Customer_N has their respective application App_N hosted on IP address at IP_N.  These all Customers have single point of entry via "Single Public URL" .  

What is best way to achieve above in dynamic way, within Nginx/openresty/lua ,  or in last option static configuration ?  


Any help will be highly appreciated. 


Igor Clark

unread,
Aug 21, 2017, 10:25:08 AM8/21/17
to openre...@googlegroups.com
Hi,

Not 100% sure what you mean - I'm not clear how you would distinguish traffic for each customer, but I guess you mean the Single Public URL would be a hostname and you'd work out which customer app to direct requests to from the URL path, right?

http://single_public_url.com/customer_1
http://single_public_url.com/customer_N
One simple way to do it would be for each customer app to have its own public URL, e.g. customer1.single_public_url.com, and the entry point (Single Public URL) would redirect via HTTP 30x to the appropriate place. That'd be really simple.

Alternatively, if the IPs aren't publicly accessible, e.g. behind NAT, you could proxy from Single Public URL to IP_N.

If I understand your requirement correctly, then if the applications speak HTTP, you don't need Lua to do this, you can just proxy directly to the appropriate app using standard nginx config:
upstream customer_1_upstream {
    server IP_1;
}

#[...]

upstream customer_N_upstream {
    server IP_N;
}

server {
    #[ listen, etc ]

    server_name single_public_url.com;

    location /customer_1 {
        proxy_pass http://customer_1_upstream;
    }

    #[...]

    location /customer_N {
        proxy_pass http://customer_N_upstream;
    }
}
(If it's a FastCGI application, you could do the same but set the appropriate IP or unix socket in "upstream" blocks and use "fastcgi_pass" instead of "proxy_pass".)

If you want to be able to route based on more complex rules, or rules that don't show in the URL - for example routing specific users to different customer apps depending on which user is associated with which app - you could write the login functionality in Lua on the gateway OpenResty host (responding to Single Public URL), and have the login code do a lookup which works out which backend to "proxy_pass" to. There's an example at https://openresty.org/en/dynamic-routing-based-on-redis.html which works out which looks up a User-Agent string in Redis, in this example you'd just want to do the user lookup in your database instead.

Hope that helps - assuming I understood what you're trying to do correctly!

Cheers
Igor

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages