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. 1.
    Before we begin, please make sure that you have a Portal API Server running by following the Portal Environment Instructions.
  2. 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.
    1
    sudo apt-get update
    2
    sudo apt-get install nginx
    Copied!
  • We can check to ensure that we have NGINX running with the following command.
    1
    systemctl status nginx
    Copied!
  • We now need to edit the nginx.conf file to redirect HTTP traffic to the internal servers.
    1
    sudo vi /etc/nginx/sites-available/formio
    Copied!
  • Put the following contents in that file.
    1
    server {
    2
    listen 80;
    3
    server_name ~^(www\.)?(.+)$;
    4
    client_max_body_size 20M;
    5
    6
    ############# Use the following for SSL ################
    7
    # listen 443 ssl;
    8
    # ssl_certificate /usr/local/etc/nginx/nginx.crt;
    9
    # ssl_certificate_key /usr/local/etc/nginx/nginx.key;
    10
    ########################################################
    11
    12
    location / {
    13
    proxy_set_header Host $host;
    14
    proxy_set_header X-Real-IP $remote_addr;
    15
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    16
    proxy_set_header X-Forwarded-Proto $scheme;
    17
    proxy_pass http://localhost:3000;
    18
    proxy_read_timeout 90;
    19
    proxy_redirect http://localhost:3000 https://$host;
    20
    }
    21
    22
    location /pdf/ {
    23
    rewrite ^/pdf/(.*)$ /$1 break;
    24
    proxy_set_header Host $host;
    25
    proxy_set_header X-Real-IP $remote_addr;
    26
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    27
    proxy_set_header X-Forwarded-Proto $scheme;
    28
    proxy_pass http://localhost:4005;
    29
    proxy_read_timeout 90;
    30
    proxy_redirect http://localhost:4005 https://$host;
    31
    }
    32
    }
    33
    34
    server {
    35
    listen 80;
    36
    server_name ~^minio.(.+)$;
    37
    client_max_body_size 20M;
    38
    39
    ############# Use the following for SSL ################
    40
    # listen 443 ssl;
    41
    # ssl_certificate /usr/local/etc/nginx/nginx.crt;
    42
    # ssl_certificate_key /usr/local/etc/nginx/nginx.key;
    43
    ########################################################
    44
    45
    location / {
    46
    proxy_buffering off;
    47
    proxy_set_header Host $http_host;
    48
    proxy_pass http://localhost:9000;
    49
    }
    50
    }
    Copied!
    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
    1
    sudo rm /etc/nginx/sites-enabled/default
    2
    sudo ln -s /etc/nginx/sites-available/formio /etc/nginx/sites-enabled/default
    3
    sudo systemctl restart nginx
    Copied!
  • 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 modified 7mo ago
Copy link