To set up Nginx as a load balancer
The settings are specified in the configuration file, C:\tools\nssm-2.24/conf/nginx.conf.
To set up Nginx as a load balancer:
Modify the settings as per your requirements.
To modify the settings:
-
Open the nginx.conf in any text editor. Default configuration contains two blocks: events
{…}
and http{…}
. -
In the nginx.conf file, remove the default http block and add a new http block as follows:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
keepalive_timeout 65;
include mime.types;
default_type application/octet-stream;
sendfile on;
client_max_body_size 200M;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" ';
upstream aeservers{
server 10.41.16.72:8080;
server 10.41.4.50:8080;
}
server {
listen 80;
access_log logs/host.access.log main;
error_log logs/host.error.log info;
underscores_in_headers on;
location ^~/aeui/ {
proxy_pass http://aeservers;
proxy_connect_timeout 300s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_request_headers on;
}
location ^~/aeengine/rest {
proxy_pass http://aeservers;
proxy_set_header Host $host;
#proxy_next_upstream error timeout invalid_header http_500;
proxy_connect_timeout 2;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_request_headers on;
}
}
}
tip
- Set proxy_send_timeout configuration parameter value considering the maximum time taken to fulfill any request through Nginx. See the Nginx resources for complete list of configuration parameters.
- Set underscores_in_headers on, so that Nginx does not silently drop HTTP headers with underscores. In the configuration file, you can modify the following settings as per your requirement and availability:
- Nginx runs on the default port number, 80. To modify the port details, go to the following line in the conf file:
server
{
listen 80;
}
- Modify the IP addresses and ports of AE servers (aeengine, aeui) as per your environment. The default IP addresses are as follows: 10.41.16.72:8080 and 10.41.4.50:8080.
- Browser and Agent will point to Nginx server. Nginx server will internally redirect the requests to one of the available AE servers (default round-robin method).
Start or stop Nginx
If Nginx is set up as a Windows Service, you can start or stop the service from the Windows Services console.