1

I am from development background and totally new to DevOps, I want to setup consul for service discovery for my micro-services, services are reverse proxied by Nginx. Now I want to configure Nginx with the consul, we are not using dockers as of now.

I have gone through many tutorials but I didn't get much about that how can I configure Nginx with the consul.

Any lead would be appreciated.

Ravat Tailor
  • 153
  • 6

1 Answers1

2

I have done this in the past using https://github.com/hashicorp/consul-template.

What consul-template does it generate a configuration file (for nginx) based on a certain template you provide. And the values that it fills into this template are coming from the configuration stored in consul.

Each time your micro-services register themselves in consul and need to be addressed in the nginx configuration file, consul-template does it for you by changing the file and sending a SIGHUP (kill -1) to the nginx process that makes it reload nginx configuration.

The repository for consule-template contains an example of managing nginx https://github.com/hashicorp/consul-template/blob/master/examples/nginx.md


If you are using Nginx Plus, which is the commercial version of Nginx. Then it has support for Consul built-in. https://www.nginx.com/blog/service-discovery-with-nginx-plus-and-consul/ and https://www.nginx.com/blog/service-discovery-nginx-plus-srv-records-consul-dns/ go into depth on this subject.

Evgeny Zislis
  • 9,023
  • 5
  • 39
  • 72