Setup NGINX as Proxy Forward and Load Balancer

You can use Nginx to proxy all requests for port 80 to 8080 or setup a Load Balancer across multiple EnterMediaDB instances.

In CentOs 7, install Nginx from Entermedia’s Repo. This version have a nginx module to add a sticky cookie to be always forwarded to the same upstream server:

  1. Enable the EnterMedia RPM repository
  2. Install our custom NGINX build that includes sticky load balancing code can be found here
    sudo yum clean all
    sudo yum -y remove nginx
    sudo yum -y install nginx-1.10.0-1.el7.centos.ngx
    sudo systemctl enable nginx
    
  3. Now create a configuration file:
    sudo vi /etc/nginx/conf.d/entermedia.conf

And put this content in the file replacing your own configs:

server {
  listen        80;
  server_name   *.domain.com domain.com;
  location / {
                    proxy_max_temp_file_size 2048m;
                    proxy_read_timeout 1200s;
                    proxy_send_timeout 1200s;
                    proxy_connect_timeout 1200s;
                    client_max_body_size 100G;
                    proxy_set_header Upgrade $http_upgrade;
                    proxy_set_header Connection "upgrade";
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Host $http_host;
                    proxy_pass http://cluster_nodes;
  }
}

upstream cluster_nodes {
  sticky;
  server 172.18.0.100:8080;
  server 10.0.0.2:8080;
}

Delete any default nginx configuration files:

sudo rm /etc/nginx/conf.d/default.conf

Reload Nginx:

sudo nginx -s reload

Test it:

curl http://xyz.domain.com/

Block access to port 8080 for external clients

sudo /sbin/iptables -A INPUT -p tcp -i eth0 --dport 8080 -j REJECT --reject-with tcp-reset

Make Nginx autostart on server reboot:

chkconfig nginx on

 

On RHEL or CentOs systems with SELinux activated, you need to edit permissions to allow httpd scripts to access the network

sudo setsebool -P httpd_can_network_connect 1