Load Balancer Configuration
You can use a custom load balancer for an API Gateway cluster. Here you use the load balancer nginx.
On a Linux machine, the load balancer configuration file /etc/nginx/nginx.conf is as follows:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log debug;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
upstream apigateway {
server localhost:5555;
server localhost:5556;
server localhost:5557;
}
server {
listen 8000;
location / {
proxy_pass http://apigateway;
}
}
}
Use sudo nginx -s reload or sudo nginx -s start to reload or start nginx. In a test environment, the command nginx-debug is used for greater debugging. The load needs to be exposed through the firewall that is protecting the host the firewall is running on.