When deploying Pilot Data Server behind a proxy server, it is often necessary to rewrite requests, to ensure the application interprets and responds to client requests correctly. This process typically involves adjusting elements of the request to account for modifications introduced by the proxy, such as altered hostnames, schemes, or paths.
There are two primary methods for aligning the application's URL with the external-facing URL used by the proxy.
Using X-Forwarded Headers
The proxy server must either populate the X-Forwarded headers or the Forwarded header in order for Pilot Data Server to serve the appropriate hostname, port and protocol in its responses:
Forwarded
X-Forwarded-Host
X-Forwarded-Port
X-Forwarded-Proto
Use a proxy server with the above headers configured. If the Forwarded
or X-Forwarded
headers are not configured, the proxy server can be configured to pass the Host
header it received from the client to Pilot Data Server.
Configure Base URL
An alternative method is to explicitly configure the application’s Base URL to match the external-facing URL provided by the proxy.
This cannot be combined with the forwarded-headers mentioned above.
Note: The Base Path cannot be combined with neither forwarded-headers nor the Base URL. The base path is only applied to the internal URL when no proxy is configured.
Redundancy and Failover
Although Pilot Data Server has been designed without built-in redundancy, it does support being used with off-the-shelf third-party HTTP load balancers. As the name suggests, a load balancer's main function is to distribute requests among multiple servers. Multiple servers provide redundancy, and most load balancers come with an option to only route requests to servers that respond, which provides failover.
Both Barracuda Load Balancer ADC and HAProxy have successfully been used in front of Pilot Data Server.
Load Balancer Quick Setup
Quickly set up a HAProxy load balancer:
Prerequisites
Two (or more) hosts running Pilot Data Server, connected to the same database. They have host names pds1.example and pds2.example for the purpose of these instructions. Static IP addresses may be used instead.
A Linux host that turns into a load balancer. It has the host name proxy.example for the purpose of these instructions. This is the host used in the installation steps below.
Installation Steps
On the Linux host, install HAProxy with the command
sudo apt-get install haproxy
.Edit /etc/haproxy/haproxy.cfg (for example with
sudo nano /etc/haproxy/haproxy.cfg
) and append the following lines:frontend http-in
bind :
8177
default_backend servers
backend servers
server server1 pds1.example:
8177
check
server server2 pds2.example:
8177
check
listen stats
bind :
80
mode http
stats enable
stats uri /
Restart HAProxy with the command
sudo service haproxy reload
.
Notes
After following the steps above, it should be possible to use proxy.example:8177 in place for pds1.example:8177 and pds2.example:8177. Check whether the setup works by opening http://proxy.example:8177/ in a browser. The Pilot Data Server index page should load.
The above configuration also provides a monitoring page at http://proxy.example/, that shows which Pilot Data Server hosts are responding. This does not tell you whether Pilot Data Server is working correctly, as hosts still respond when they cannot reach the database.