
所以這就是問題所在:
負載平衡器 (haproxy) 交付給 3 個 Web 伺服器和一個資料庫伺服器,總共 5 個伺服器,memcache 會話在 Web 伺服器之間共用。我可以確認它PHPSESSIONID
在網頁伺服器之間共享,但是當我嘗試登入時,$_POST
不斷重置並且登入的 cookie 從未設置,導致不斷重定向到登入頁面。
我已經設定了appsessionid
haproxy 並且可以工作,但是它違背了我心中使用負載平衡器的目的,因為大多數用戶都會登錄,所以很可能一台伺服器會比其他伺服器收到更多的流量。有沒有人遇到過這個問題以及如何解決它的想法?或者我被迫使用粘性會話?
編輯1:
做了更多研究並意識到我可以保存$_POST
在 中$_SESSION
,但可能存在一些安全問題。我的想法是在每個頁面的關閉操作中將其從會話中擦除。想法?
編輯2:
這是/etc/haproxy/haproxy.cfg
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
daemon
user haproxy
group haproxy
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL).
tune.ssl.default-dh-param 2048
ssl-default-bind-ciphers LONG LIST OF CIPHERS
defaults
log global
balance leastconn
mode http
option httplog
option dontlognull
option redispatch
option http-server-close
option forwardfor
option abortonclose
maxconn 3000
retries 3
timeout queue 1m
timeout connect 10s
timeout client 5m
timeout server 5m
timeout http-request 5s
timeout http-keep-alive 10s
timeout check 10s
frontend www-http
bind xxx.xxx.xxx.xxx:80
reqadd X-Forwarded-Proto:\ http
redirect scheme https if !{ ssl_fc }
default_backend wordpress-backend
frontend www-https
bind xxx.xxx.xxx.xxx:443 ssl no-sslv3 crt /etc/ssl/private/default.pem crt /etc/ssl/private/
rspadd Strict-Transport-Security:\ max-age=15768000
reqadd X-Forwarded-Proto:\ https
default_backend wordpress-backend
backend wordpress-backend
option httpchk HEAD /haphealth
server wordpress-1 xxx.xxx.xxx.xxx:8081 maxconn 10 check
server wordpress-2 xxx.xxx.xxx.xxx:8081 maxconn 10 check
server wordpress-3 xxx.xxx.xxx.xxx:8081 maxconn 10 check
答案1
我知道這是一個舊線程,但想知道 Web 伺服器上是否有一些 303 重定向。在這種情況下,用戶端將重試 GET,並且 POST 資料將會遺失。請改用 307 重定向。
答案2
我在同一頁面上同時返回安全 (https) 和不安全 (http) 資料的網站上使用此方法:
frontend WordPress
mode http
option httplog
bind <ip_address>:80 transparent
bind <ip_address>:443 transparent ssl crt <path_to_cert>
http-request set-header X-Forwarded-Proto https # <------ This is the line makes sure everything that's requested is HTTPS
redirect scheme https code 307 if !{ ssl_fc }
default_backend wp_backend
然後我從 ' 更新了該網站的 WP 配置http://some_site.com' 到 'https://some_site.com'。
這正如預期的那樣。