2
votes

I have multiple upstream servers from an nginx load balancer:

upstream app {
  # Make each client IP address stick to the same server
  # See http://nginx.org/en/docs/http/load_balancing.html
  ip_hash;

  # Use IP addresses: see recommendation at https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
  server 1.1.1.1:6666; # app-server-a
  server 2.2.2.2:6666; # app-server-a
}

Right now I ue the servers in an active/passove configuration by taking down each servers (eg systemctl myapp stop) then letting nginx detect the server is down.

However I'd like to be able to change the upstream server dyamically, without having to take either app server or nginx OSS down. I'm aware of the proprietary upstream_conf module for nginx Plus but am using nginx OSS.

How can I dynamically dynamically reconfigure the upstream server on nginx OSS?

1

1 Answers

1
votes

You can use:

  • openresty an OSS nginx bundle with lua scripting ability

  • nginx with lua scripting (you can configure it by yourself using nginx OSS and luajit) to achieve this.

  • dynx can achieve exactly what you are looking for, it's still work in progress but the dynamic upstream functionality is there and it's configurable through a rest API.

I'm adding the details on how to deploy and configure dynx:

  • you need to have a docker swarm up and running (for testing purpose you can have a 1 swarm machine), follow the docker documentation to do that.
  • after you need to deploy the stack, for example, with this command (you need to be on the dynx git root):

    docker stack deploy -c docker-compose.yml dynx

To check if the application deployed correctly, you can use this command:

docker stack services dynx

To configure an location you can use through the api you can for instance do:

curl -v "http://localhost:8888/configure?location=/httpbin&upstream=http://www.httpbin.org/anything&ttl=10"

To test if it works:

curl -v http://localhost:8666/httpbin

Do not hesitate to contact me or open an issue on github if you are not able to get it to work