Reverse Proxy and Load Balancer Configuration

NGINX

Nginx is a web server which can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. It is very easy to setup, configure and it has very good documentation.

The following example shows how to configure a load balancer, redirect all HTTP requests to HTTPS and how to proxy requests.

http {
...
    # Load balancer
    upstream registry-cluster {
        server api1.test.local:8000;
        server api2.test.local:8000;
        server api3.test.local:8000;
    }

    # Redirect all HTTP requests to HTTPS
    server {
        listen       80;
        server_name  _;
        return 301 https://$host$request_uri;
    }

    # Proxy
    server {
        listen       443 ssl;
        ...
        location /registry {
            proxy_pass http://registry-cluster/registry-api/;
        }
    }
}

Apache HTTP Server

Apache HTTP Server can act as a web server, reverse proxy and a load balancer.

To enable reverse proxy and load balancer features, uncomment these modules in httpd.conf

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so

LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so

To redirect all HTTP requests to HTTPS you can use the following commands

<VirtualHost *:80>
    Redirect permanent / https://www.myhost.com/
</VirtualHost>

Example load balancer and proxy configuration is shown below

<Proxy balancer://registry-cluster>
    BalancerMember http://api1.test.local:8000
    BalancerMember http://api2.test.local:8000
    BalancerMember http://api3.test.local:8000
</Proxy>

<VirtualHost *:443>
    ...
    ProxyPass           /registry balancer://registry-cluster/registry-api/
    ProxyPassReverse    /registry balancer://registry-cluster/registry-api/
</VirtualHost>