haproxy 後面的 nginx - 頁面隨機加載,無論提交的網域如何

haproxy 後面的 nginx - 頁面隨機加載,無論提交的網域如何

我目前有一台運行nginx 的Web 伺服器(10.0.0.77),帶有多個虛擬主機(幾個WordPress 網站和nextcloud 安裝),所有虛擬主機都在1 個IP 位址上運行,並且所有內容都透過通配符證書進行保護。效果很好——無論是內部還是外部

現在我想透過 HAproxy 代理所有外部流量,以下是我針對一個 wordpres 網站和 nextcloud 的簡化 haproxy 設定:

global
log /dev/log    local0
log /dev/log    local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
maxconn 4096
user haproxy
group haproxy
daemon


defaults
log     global
mode    tcp
option  tcplog
option  dontlognull
timeout connect 15s
timeout client  15s
timeout server  15s
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http


frontend localhost80  
bind *:80
mode http
redirect scheme https code 301 if !{ ssl_fc }

frontend localhost443   
bind *:443
option tcplog
mode tcp
acl tls req.ssl_hello_type 1
tcp-request inspect-delay 5s
tcp-request content accept if tls

acl is_wordpress req.ssl_sni -i nextcloud.domain.com   
acl is_nextcloud req.ssl_sni -i wordpress.domain.com  

use_backend nextcloud_cluster if is_nextcloud  
use_backend wordpress_cluster if is_wordpress

backend wordpress_cluster
mode tcp
option ssl-hello-chk
server is_wordpress 10.0.0.77:443 check 


backend nextcloud_cluster
mode tcp
option ssl-hello-chk
server is_nextcloud 10.0.0.77:443 check

問題是,一旦我重新指向外部流量以通過我的 haproxy 運行,如果我嘗試 loding ie。 nextcloud.domain.com 我有時會得​​到 wordpress.domain.com,反之亦然。

有什麼想法我哪裡出錯了嗎?

答案1

當使用 SNI 區分後端時,您應該注意,在這種特定情況下,非 SNI 用戶端將無法存取網站。

但是,如果這對您的客戶端來說沒問題,並且您仍然平衡到同一後端(如範例中所示),那麼您的配置中仍然有冗餘資訊。這裡更簡單的方法是:

frontend localhost443   
  bind *:443
  option tcplog
  mode tcp
  default_backend backend1

backend backend1
  mode tcp
  option ssl-hello-chk
  server server1 10.0.0.77:443 check 

由於您的設定只是第4 層平衡,如果您仍然獲得隨機網站,則必須更仔細地查看在10.0.0.77:443 上運行的網站伺服器:哪個網路伺服器,它是如何設定的,它是否產生相同的結果直接存取有問題嗎?

相關內容