Haproxy ssl 重定向

Haproxy ssl 重定向

我不確定我是否理解 haproxy 的工作原理。我的系統由幾個基於http 通訊的伺服器組成。我想同時使用 haproxy 作為負載平衡器和 https 伺服器之類的東西。它應該按以下方式工作:使用者寫入位址並由 haproxy 決定 - 如果是 http,則將其重定向到 https,如果是 https,則透過 http 與系統連接。我的意思是只有具有 haproxy 的客戶端才應具有 https 連接,但具有系統的 haproxy 應該具有 http。這是包含所描述架構的圖像:

在此輸入影像描述

我寫了 haproxy 配置文件,只有我得到的是從 http 重定向到 https 並顯示第一個站點 - 其餘的都死了,因為所有通信看起來像:

客戶端 --(https)--> haproxy --(https)-->系統

代替

客戶端 --(https)--> haproxy --(http)-->系統

是否可以使用 haproxy 來建立它?

以下是我的 haproxy 設定檔:

global
    pidfile /var/run/haproxy.pid
    log 127.0.0.1 local2 debug
    maxconn 2048
    tune.ssl.default-dh-param 2048
    ca-base /etc/ssl/certs
    crt-base /etc/ssl/private

defaults
    mode        http
    option forwardfor
    option http-server-close
    log global
    option      httplog
    option dontlognull
    option forwardfor
    option http-server-close
    option redispatch
    option tcp-smart-accept 
    option tcp-smart-connect
    timeout http-request 10s
    timeout queue 1m
    timeout connect 5s
    timeout client 2m
    timeout server 2m
    timeout http-keep-alive 10s
    timeout check 5s
    retries 3
    compression algo gzip
    compression type text/html text/html;charset=utf-8 text/plain text/css text/javascript application/x-javascript application/javascript application/ecmascript application/rss+xml application/atomsvc+xml application/atom+xml application/atom+xml;type=entry application/atom+xml;type=feed application/cmisquery+xml application/cmisallowableactions+xml application/cmisatom+xml application/cmistree+xml application/cmisacl+xml application/msword application/vnd.ms-excel application/vnd.ms-powerpoint

frontend https-in
    bind *:80
    redirect scheme https if !{ ssl_fc }
    bind *:443 ssl crt /etc/ssl/private/cert.pem
    capture request header X-Forwarded-For len 64
    capture request header User-agent len 256
    capture request header Cookie len 64
    capture request header Accept-Language len 64
    rspadd Strict-Transport-Security:\ max-age=15768000
    option contstats
    default_backend share-https

backend share-https
    option httpchk GET /share
    balance roundrobin
    cookie JSESSIONID prefix
    server main srv1:9080 cookie main check inter 5000 weight 4
    server secondary srv2:9080 cookie secondary check inter 5000 weight 1

答案1

問題是因為我描述的系統是 Alfresco - 名為「共享」的應用程式具有阻止 https 的 CSRFPolicy。根據這個解決方案

  1. 從下列位置複製“CSRFPolicy”預設配置:

TOMCAT_HOME/webapps/share/WEB-INF/classes/alfresco/share-security-config.xml

到:

TOMCAT_HOME/shared/classes/alfresco/web-extension/share-config-custom.xml

  1. 新增屬性replace=“true”:

<config evaluator="string-compare" condition="CSRFPolicy" replace="true">

  1. 更新屬性推薦人起源帶有 Apache VirtualHost 的 FQDN (https)

<referer>https://HAProxyAddress/.*</referer> <origin>https://HAProxyAddress</origin>

就這樣。這個對我有用。

相關內容