为 HAProxy 配置 SSL/TLS
使用 ThingWorx HA 群集时,可以为 HAProxy 配置 SSL 或 TLS。
可以将 HAProxy 设置为使用外部 SSL 和内部 SSL。您必须提供证书文件。不能使用 passthrough SSL,因为 ThingWorx 需要请求对象的访问权限来进行基于路径的路由。有多个选项可用于在 HAProxy 中配置 SSL。以下内容仅用于参考;有关详细信息,请参阅 https://cbonte.github.io/haproxy-dconv/2.0/configuration.html
从客户端到 HAProxy 的外部 SSL
global 配置中,您可以为证书和私钥设置可选的默认位置。在前端配置中,您可以配置密码以及支持的 TLS 级别。例如:
global
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
# An alternative list with additional directives can be obtained from
# https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3
前端部分是传入端点的位置。应该在此配置要使用的绑定端口和证书。有关绑定配置的详细信息,请参阅 https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#5.1
例如:
frontend ft_web
bind *:8443 ssl crt /certs/haproxy.pem name sslweb
* 
如果已在 ThingWorx HA 环境中安装 ThingWorx Flow,则必须绑定端口和证书。
从 HAProxy 到应用程序的内部 SSL
将针对每个后端服务器配置内部 SSL。每台服务器都可以采用不同的设置。在以下示例中,所有平台服务器均支持 SSL,并在端口 8443 上接收请求。已将服务器端点配置为指向该位置并使用 SSL。此示例使用自签名证书,因此,请验证其是否已设置为 none。有关服务器配置选项的详细信息,请参阅 https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#5.2
backend platform
server platform1 platform1:8443 ssl verify none
server platform2 platform2:8443 ssl verify none
ThingWorx Flow 的示例
如果已在 ThingWorx HA 环境中安装 ThingWorx Flow,请添加后端 ThingWorx Flow 配置信息:
backend flow
server nginx <NGinx_IP>:443 check ssl verify none
创建自签名证书
例如:
openssl req -newkey rsa:2048 -nodes -x509 -days 365 -keyout haproxy.key -out haproxy.crt -subj "/CN=$HAPROXY_SSL_SERVER_CERT_CN" && \
cat haproxy.crt haproxy.key >> /certs/haproxy.pem
chmod 755 /certs/haproxy.pem && \
ThingWorx Flow 的示例
如果已在 ThingWorx HA 环境中安装 ThingWorx Flow,请执行以下操作:
1. 创建 / 下包含所有必要权限的 certs 文件夹
2. 运行以下命令来创建证书:
sudo openssl req -newkey rsa:2048 -nodes -x509 -days 365 -keyout haproxy.key -out haproxy.crt -subj “/CN=<Load_Balancer_Host>” && sudo cat haproxy.crt haproxy.key >> /certs/haproxy.pem
此命令将在 /etc/haproxy 文件夹下创建 haproxy.crthaproxy.cfg,在 /certs 文件夹下创建 haproxy.pem
使用 Docker
您可以使用官方 HAProxy 容器并在 certshaproxy.cfg 文件中安装。内部 HAProxy 容器支持以下配置:
PLATFORM_ADDRESSES: platform1,platform2,platform3
CXSERVER_ADDRESSES: cxserver1,cxserver2
HAPROXY_STAT_USER: admin
HAPROXY_STAT_PASSWORD: thingworx
SSL_ENABLED: true
SSL_CERT_PATH: /certs/haproxy.pem
LOG_LEVEL: debug
PLATFORM_SECURE: true
PLATFORM_SECURE_PORT: 8443
PLATFORM_PORT: 8080
CXSERVER_SECURE: true
CXSERVER_SECURE_PORT: 8443
CXSERVER_PORT: 8080
FLOW_SECURE: true
FLOW_SECURE_PORT: 443
FLOW_PORT: 80
证书应安装到 /certs 文件夹:
haproxy:
image: artifactory.rd2.thingworx.io/twxdevops/tw-lb-haproxy:latest
container_name: haproxy
ports:
- 9100:8080
- 9143:8443
- 1936:1936
environment: *haproxy-env
volumes:
- certs:/certs
这对您有帮助吗?