看板 Knuckles_note
作者 標題 [Linode] NodeBalancer 的 SSL (https) 設定
時間 2014年03月04日 Tue. PM 10:08:11
Linode 提供的負載平衡器服務 NodeBalancer
在 2013/11 開始可以支援 SSL (https)
https://blog.linode.com/2013/11/07/nodebalancer-ssl/
![[圖]](http://knuckles.disp.cc/pic/pick/20140304_001_32.png)
只要將SSL的 private key 和 crt 提供給 NodeBalancer
NodeBalancer 就可以解出 https 連線的封包,轉為 http 再傳給主機
https http
Client -------> NodeBalancer ------> Server
:443 :80
NodeBalancer 會將 Client 的IP位址存到 HTTP header 的 X-Forwarded-For
Server 就可以透過 PHP 的 $_SERVER['HTTP_X_FORWARDED_FOR'] 取得真實IP
如果 SSL 是依這篇的設定:
http://disp.cc/b/11-3UNW Apache 使用 GoDaddy 的 SSL (https)加密連線設定
Certificate 就是從 GoDaddy 下載的兩個檔
xxxxxxxxxxxxxxxx.crt、gd_bundle-xx-xx.crt
將內容依序貼上
Private Key 就貼上 /etc/pki/tls/private/ca2048.key 的內容
如果 SSL 是依這篇 [CentOS7] 使用 Certbot 申請 Let's Encrypt 的SSL憑證
那就將產生的 fullchain.pem 與 privkey.pem 分別用來輸入 SSL Certificate 與 Private Key
參考這篇: [Linode] NodeBalacer使用Let's Encrypt SSL憑証
注意這樣對 Server 來說就不能用 $_SERVER['HTTPS'] 來分辨連線是否為 https 了
可以改用 $_SERVER['HTTP_X_FORWARDED_PROTO'] == "https" 來判斷是否為 https
也可以在 Apache 的設定 vhost.conf 中加上
SetEnvIf X-Forwarded-Proto https HTTPS=on
這樣 $_SERVER['HTTPS'] 就會變成 on
如果想讓 http 的連結自動跳轉至 https 的話
可以在 Apache 設定檔或是 .htaccess 使用 Rewrite
例如要讓 http://disp.cc/xxx 自動跳轉至 https://disp.cc/xxx
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteCond %{HTTP_HOST} ^disp.cc$
RewriteRule ^(.*)$ https://disp.cc/$1 [R=301,L]
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteCond %{HTTP_HOST} ^disp.cc$
RewriteRule ^(.*)$ https://disp.cc/$1 [R=301,L]
--
※ 作者: Knuckles 時間: 2014-03-04 22:08:11
※ 編輯: Knuckles 時間: 2023-11-27 14:38:55 (台灣)
※ 看板: KnucklesNote 文章推薦值: 0 目前人氣: 0 累積人氣: 940
回列表(←)
分享