NGINX 示例
NGINX 提供代理功能和 Web 服务器选项。下面的示例仅设置负载均衡器。某些功能 (如粘滞会话) 在免费版本中未提供,而是需要升级到 NGINX Plus。
前端设置
对于 NGINX 的前端设置,您需要配置包含端口和路由规则的服务器。
listen
等效于 HAProxy bind,即应用程序将与之对话的外部端口。
location
基于 path 的路由规则,与在 HAProxy 中类似。
默认情况下,所有通信都将转至 / 位置并传递至上游 thingworx 组。
Connection Server 的位置匹配将使用正则表达式,而不是列出每个路径。这些内容将传递至上游 cxserver 组。
例如:
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;
}
}
平台后端设置
此部分是可处理请求和负载平衡算法的服务器的列表。
ip_hash
向服务器发出基于 IP 地址的粘滞请求。粘滞会话是 NGINX Plus 中的一项功能。
server
列表中为每个服务器提供了一些条目。
未配置运行状况检查,但如果服务器失败,则会重新路由通信。运行状况检查是 NGINX Plus 提供的一项功能。
例如:
upstream thingworx {
ip_hash;
server platform1:80;
server platform2:80;
}
Connection Server 后端设置
ip_hash
向服务器发出基于 IP 地址的粘滞请求。这相当于 HAProxy 中的 source
服务器
列表中为每个服务器提供了一些条目。
未配置运行状况检查,但如果服务器失败,则会重新路由通信。运行状况检查是 NGINX Plus 提供的一项功能。
例如:
upstream cxserver {
ip_hash;
server cxserver1:80;
server cxserver2:80;
}
完整示例
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;
}
}
}
这对您有帮助吗?