針對 HAProxy 配置 SSL/TLS
使用 ThingWorx HA 叢集時,您可針對 HAProxy 配置 SSL 或 TLS。
您可以針對外部 SSL 與內部 SSL 設定 HAProxy。您必須提供憑證檔案。您無法使用直通 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。此範例使用自我簽署憑證,因此 verify 設定為 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
這是否有幫助?