Is there a programmatic interface to nginx configuration?
I am using nginx as a load balancer in front of my web server instances. I run 4 instances of the web server and spread the traffic equally across them using nginx. When I am deploying new version - I change the nginx.conf and mark first 2 of the 4 servers down, then restart nginx. I update the server code and restart the first 2 servers. Then I edit nginx.conf to indicate that the first 2 servers are up and mark the other 2 down, again restart nginx. Then I update and restart other two instances. Again update the nginx.conf marking all servers up and final restart of nginx.
I have to do this process multiple times on some days. Manually performing the above steps every time turns out to be error prone.
Is there a programmatic access to nginx/nginx.conf so that I can automate this process?
[The only way I imagine right now is to write above steps in shell script]
Solution 1:
No, nginx does not have a configuration API.
Although there are cases when you might need to manually mark servers as down, generally configuring proxy_next_upstream + fail_timeout will work.
Solution 2:
There is now nginx-conf, an NPM module that provides programmatic access to nginx configurations.