[英]HAProxy + Nodejs + SockJS + Express + SSL
我在NodeJS中有一個服務器設置,如下圖所示:
現在我想做兩件似乎可以用HAProxy
做的事情:
無論客戶端想要訪問什么服務器,只能使用一個端口。 我想將外部端口
8080
用於所有非SSL流量。 (所有SSL流量都應使用端口443)在
SockJS Server
和Express Server
上啟用SSL。
請注意,我所有的服務器都在amazon ec2
上的同一個實例上運行。 所以我想在內部路由流量。
到目前為止,這是我的haproxy.cfg
:
mode http
# Set timeouts to your needs
timeout client 10s
timeout connect 10s
timeout server 10s
frontend all 0.0.0.0:8080
mode http
timeout client 120s
option forwardfor
# Fake connection:close, required in this setup.
option http-server-close
option http-pretend-keepalive
acl is_sockjs path_beg /echo /broadcast /close
acl is_stats path_beg /stats
use_backend sockjs if is_sockjs
use_backend stats if is_stats
default_backend express
backend sockjs
# Load-balance according to hash created from first two
# directories in url path. For example requests going to /1/
# should be handled by single server (assuming resource prefix is
# one-level deep, like "/echo").
balance uri depth 2
timeout server 120s
server srv_sockjs1 127.0.0.1:8081
backend express
balance roundrobin
server srv_static 127.0.0.1:8008
backend stats
stats uri /stats
stats enable
無法弄清楚如何將SSL和流量路由到TCP Server
(8080內部端口)
有任何想法嗎?
你的設置有點難以理解(對我而言)。 如果我正確理解您的目標,您希望通過SSL服務您的Web服務,因此端口443.從443,連接到端口8080(內部)。 如果是這種情況,那么以下配置可能就是您要查找的內容。 它並不真正使用端口8080,而是直接連接到您的express
后端。 您實際上不需要暴露端口8080(除非您有特殊原因),因為您可以直接在前端部分內使用后端服務器。
請注意,這僅適用於HAProxy 1.5+,如果您使用的是舊版本的HAProxy,您應該在SSL連接到達HAProxy之前添加一些內容(但我強烈建議使用1.5,因為它會使您的設置不那么復雜)
frontend ssl
bind *:443 ssl crt /path/to/cert.pem ca-file /path/to/cert.pem
timeout client 120s
option forwardfor
# Fake connection:close, required in this setup.
option http-server-close
option http-pretend-keepalive
acl is_sockjs path_beg /echo /broadcast /close
acl is_stats path_beg /stats
use_backend sockjs if is_sockjs
use_backend stats if is_stats
default_backend express
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.