NGINX Example
NGINX provides proxy capabilities and Web server options. The following example sets up the load balancer only. Some features like sticky sessions are not available in the free version and require an upgrade to NGINX Plus.
Frontend Settings
For the frontend settings for NGINX, you configure servers, which contain the port and routing rules.
listen
Equivalent to HAProxy bind, the external port to which the application will talk.
location
Routing rules, based on path just like in HAProxy.
All traffic goes to the / location by default and passes to the upstream thingworx group.
The location match for Connection Server uses a regex instead of listing each path. These will pass to the upstream cxserver group.
For example:
server {
listen 80;

# connection server paths
location ~ ^/Thingworx/(WS|WSTunnelClient|WSTunnelServer|TWS)\.* {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://cxserver;
}

# everything else to thingworx
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://thingworx;
}
}
Platform Backend Settings
This section is the list of servers that can handle requests and the load balance algorithm.
ip_hash
Makes the request sticky to a server based on IP address. Sticky sessions is a feature in NGINX Plus.
server
There are entries for each server in the list.
No health checks are configured, but if a server fails, traffic is rerouted. Health checks are a feature of NGINX Plus.
For example:
upstream thingworx {
ip_hash;
server platform1:80;
server platform2:80;
}
Connection Server Backend Settings
ip_hash
Makes the request sticky to a server based on IP address. This is equivalent to source in HAProxy.
server
There are entries for each server in the list.
No health checks are configured, but if a server fails, traffic is rerouted. Health checks are a feature of NGINX Plus.
For example:
upstream cxserver {
ip_hash;
server cxserver1:80;
server cxserver2:80;
}
Full Example
worker_processes 5; ## Default: 1

events {
}

http {
resolver 127.0.0.11:53 valid=30s;

upstream thingworx {
ip_hash;
server platform1:80;
server platform2:80;
}

upstream cxserver {
ip_hash;
server cxserver1:80;
server cxserver2:80;
}

server {
listen 80;

# connection server paths
location ~ ^/Thingworx/(WS|WSTunnelClient|WSTunnelServer|TWS)\.* {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://cxserver;
}

# everything else to thingworx
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://thingworx;
}
}
}
Was this helpful?