Skip to main content
Version: 2.x

Backend Nginx Routing

Currently in projects that use DATA-VIZ-API we have use Eureka to register services and Spring Gateway for routing and load balancing of the services registered in Eureka.

BUT in some cases, rarely I hope, we can decide to replace the Spring Gateway with a purely Nginx based routing solution.

To achieve this we have modified the deploy project and add a python service in deploy.

Deploy Python

The python service contains a script which gets all services registred in Eureka and creates urls which are registered in /etc/nginx/custom_conf. The registered urls in the python service are then shared to the nginx service as volumes, which nginx uses for reverse proxy for routing. The script will run every 30 seconds (you can choose the time you want the schedular to run) check if there is another registred service in Eureka and created a url for it.

In docker-compose.yml the python script is presented using this container nginx-routing-script.

In order to make the created urls available to nginx, this 2 files should be included in nginx.conf files.

This contains the upstreams

# Include dynamically generated upstream configurations
include /etc/nginx/custom_conf/upstreams.conf;

This contains the locations

# Include dynamically generated upstream configurations
include /etc/nginx/custom_conf/locations.conf;

NOTE This is another option if you want to use NGINX insead of Spring Gateway, BUT its better to use Spring Gateway as it has more improved ways of load balancing.