News for hackers. Stuff that matters.
Re:Nginx with dynamic upstreams by corobo on Sunday July 26, 2015 @12:51PM (#9951514)
Thank you for this, it's a decent start for me personally. I was previously using the DNS director in Varnish 3.x to do this which was removed in 4.x. The longer time goes on the more risk it is to be running older software so this has been a great help.

Oddly enough I'd never really considered nginx for the job despite using it to reverse proxy elsewhere. Sometimes you just need a poke in the right direction :)

Now I just need to figure a way to specify *.internaldomain so that nginx resolves www.example.com.internaldomain - where www.example.com is grabbed from the requested Host: header

Re:Nginx with dynamic upstreams by tombozi on Sunday July 26, 2015 @12:59PM (#9951535)
You can use the $host variable

See: http://nginx.org/en/docs/http/ngx_http_core_module.html#var_... And: http://stackoverflow.com/a/15414811

Always be careful with user input though.

Re:Nginx with dynamic upstreams by corobo on Sunday July 26, 2015 @01:24PM (#9951621)
well damn that's such a simple solution if that variable works in proxy_pass.. One of those "How did I miss that?" solutions

Of course rigorous testing before going live, but it gives options. I love options :)

Re:Nginx with dynamic upstreams by Tenzer on Sunday July 26, 2015 @12:59PM (#9951533)
It's good to hear it was of use to somebody :)

I know you can use a map in Nginx to do what you ask for, as long as you have a list of domains already: http://nginx.org/en/docs/http/ngx_http_map_module.html#map. I can only imagine it also being possible to make fully dynamic, I just don't have a clear way of doing it in mind right now.

Re:Nginx with dynamic upstreams by sprobertson on Sunday July 26, 2015 @04:44PM (#9952147)
Lua + Redis is a nice way to do this, I have a small project https://github.com/spro/simon that does dynamic routing and load balancing based on Hostname -> IP:Port sets in Redis. Adding a new route is as simple as:

  sadd backends:hnapi.dev 192.168.0.42:10555
Re:Nginx with dynamic upstreams by Tenzer on Monday July 27, 2015 @12:16AM (#9953302)
Neat! I want to get started on some Lua scripting as well, probably first to just get a bunch of metrics out of Nginx via StatsD. There's access to a whole bunch of numbers via Lua that you otherwise can't get out from the stub_status page.
Re:Nginx with dynamic upstreams by corobo on Sunday July 26, 2015 @01:25PM (#9951625)
The sibling comment to this pointed out the $host variable. I imagine something along the line of proxy_pass http://$host.internaldomain; or something on that line.

I'll have to look into it further :)