Load Balancer Configuration

In many cases, you would like to have the API Server and the PDF Server reside within the same "instance" and then route traffic to the correct container based on the traffic coming into the deployment. To achieve this, you can use a popular tool called NGINX to serve as a reverse proxy to these internal containers. The following illustrates how this can be done.

Setup

  1. Before we begin, please make sure that you have a Portal API Server running by following the Portal Environment Instructions.

  2. Next, you will want to have a running PDF Server by following the PDF Server Setup instructions.

Once you have both of these containers running, you will then run the following to install NGINX

NGINX Setup

In order to bring all of these locally hosted servers into a single HTTP interface, we can use NGINX to sit in front of these servers.

To setup this configuration, please go through the following steps.

  • Install NGINX using the following command.

    sudo apt-get update
    sudo apt-get install nginx
  • We can check to ensure that we have NGINX running with the following command.

    systemctl status nginx
  • We now need to edit the nginx.conf file to redirect HTTP traffic to the internal servers.

    sudo vi /etc/nginx/sites-available/formio
  • Put the following contents in that file.

    server {
      listen 80;
      server_name  ~^(www\.)?(.+)$;
      client_max_body_size 20M;
         
      ############# Use the following for SSL ################
      # listen               443 ssl;
      # ssl_certificate      /usr/local/etc/nginx/nginx.crt;
      # ssl_certificate_key  /usr/local/etc/nginx/nginx.key;
      ########################################################
         
      location / {
        proxy_set_header    Host $host;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto $scheme;
        proxy_pass          http://localhost:3000;
        proxy_read_timeout  90;
        proxy_redirect      http://localhost:3000 https://$host;
      }
       
      location /pdf/ {
        rewrite ^/pdf/(.*)$ /$1 break;
        proxy_set_header    Host $host;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto $scheme;
        proxy_pass          http://localhost:4005;
        proxy_read_timeout  90;
        proxy_redirect      http://localhost:4005 https://$host;
      }
    }
       
    server {
      listen 80;
      server_name  ~^minio.(.+)$;
      client_max_body_size 20M;
         
      ############# Use the following for SSL ################
      # listen               443 ssl;
      # ssl_certificate      /usr/local/etc/nginx/nginx.crt;
      # ssl_certificate_key  /usr/local/etc/nginx/nginx.key;
      ########################################################
         
      location / {
        proxy_buffering off;
        proxy_set_header Host $http_host;
        proxy_pass http://localhost:9000;
      }
    }

    Note, for this configuration to work with Minio, you will need to create a subdomain @ http://minio.yourserver.com that points to this server. Minio does not support being hosted outsiide of the root domain.

  • Now save that file, and then switch this out for the default server

    sudo rm /etc/nginx/sites-enabled/default
    sudo ln -s /etc/nginx/sites-available/formio /etc/nginx/sites-enabled/default
    sudo systemctl restart nginx
  • We can now test that we have both an API server and a PDF Server running by going to the following URLs in our Browser.

    • http://yourdomain.com/status (should show the API Server status)

    • http://yourdomain.com/pdf/ (should show the PDF Server status)

Last updated