Using confd and Nginx for edge services

Concept Description


Confd is a lightweight configuration management tool, source code: [] (, which stores configuration information in etcd, Consul, dynamodb, redis, and zookeeper. Confd periodically pulls the latest configuration from these storage nodes, then reloads the service and completes the configuration file update.


Nginx (engine x) is a high-performance HTTP and reverse proxy server with load balancing capabilities. For details, please refer to [] ( The services introduced in this section mainly use the Nginx http proxy function.

Scene Description

The technology introduced in this section is to use nginx+confd as the edge service. At the same time, you can dock the service center in the Java Chassis microservices framework, and pull the service information from the service center to dynamically update the nginx configuration through confd.

The implementation steps of using nginx+confd dynamic reverse proxy can be found in the article [] ( Html), this section mainly introduces how confd docks the service center of the Java Chassis framework.

Docking Service Center

The core of the technology introduced in this section is how to make confd get the service information of the service center. The service center opens the following interfaces for external calls:

Method one: http call

The service provider open http interface needs to add the tenant header information: "X-Tenant-Name:tenantName", and the tenameName is the tenant name. The default is default, for example, "X-Tenant-Name: default".

  • Check the health status of the service center


  • Get all micro service information


  • Get the microservice information of the specified id
  1. First get the serviceId based on the microservice information


    1. Obtain the microservice complete information according to the serviceId returned by the above interface.


  • Get all instance information for the specified microservice

```    GET{serviceId}/instances

Need to add in the header: "X-ConsumerId: {serviceId}".   ```

  • Find micro service instance information

```    GET{appId}&serviceName={serviceName}&version={version}

Need to add in the header: "X-ConsumerId: {serviceId}".   ```

Note: In actual development, please visit the actual service-center access address, and replace the variable of {} in the above url with a specific value. The data returned by http is in json format.

Method 2: Use servicecomb open source code interface

In the development of microservices applications, you only need to call the interface provided in the tool class in the servicecomb framework code to get the information of the service center. The interface description is as follows:

  • Get all micro service information

java   List<Microservice> getAllMicroservices();

  • Get the microservice unique identifier

java   String getMicroserviceId(String appId, String microserviceName, String versionRule);

  • Query microservice static information based on microservice unique identifier

java   Microservice getMicroservice(String microserviceId);

  • Query all micro service instance information based on multiple microservice unique identifiers

java   List<MicroserviceInstance> getMicroserviceInstance(String consumerId, String providerId);

  • Query instance endpoints information by app+interface+version

java   List<MicroserviceInstance> findServiceInstance(String consumerId, String appId, String serviceName, String versionRule);

Through the above http interface, information about the microservices of the service center and its instances can be obtained, thereby dynamically updating the nginx configuration through confd.