phpBB3在使用Cloudflare Proxy下的設定

By | 08/09/2021

系統環境 : Ubuntu 20.04 LTS , Apache2 , phpBB 3.3.4

問題 : 當流量經過Cloudflare Proxy後 , phpBB3無法正確抓取用戶真實的IP , 導致不斷重複整個登入ACP的要求

phpBB3紀錄檔 :

解決方法 :

參考Cloudflare的幫助文檔 : https://support.cloudflare.com/hc/en-us/articles/200170786

使用mod_remoteip讓伺服器正確取得用戶IP

啟用mod_remoteip

sudo a2enmod remoteip

更改Apache2 Site Conf

sudo vi /etc/apache2/sites-enabled/002-forum.conf

在Servername下方新加一行

RemoteIPHeader CF-Connecting-IP

確認儲存及離開

新增remoteip.conf及加入Cloudflare Proxy IP

sudo vi /etc/apache2/conf-available/remoteip.conf

RemoteIPHeader CF-Connecting-IP
RemoteIPTrustedProxy 173.245.48.0/20
RemoteIPTrustedProxy 103.21.244.0/22
RemoteIPTrustedProxy 103.22.200.0/22
RemoteIPTrustedProxy 103.31.4.0/22
RemoteIPTrustedProxy 141.101.64.0/18
RemoteIPTrustedProxy 108.162.192.0/18
RemoteIPTrustedProxy 190.93.240.0/20
RemoteIPTrustedProxy 188.114.96.0/20
RemoteIPTrustedProxy 197.234.240.0/22
RemoteIPTrustedProxy 198.41.128.0/17
RemoteIPTrustedProxy 162.158.0.0/15
RemoteIPTrustedProxy 104.16.0.0/12
RemoteIPTrustedProxy 172.64.0.0/13
RemoteIPTrustedProxy 131.0.72.0/22
RemoteIPTrustedProxy 2400:cb00::/32
RemoteIPTrustedProxy 2606:4700::/32
RemoteIPTrustedProxy 2803:f800::/32
RemoteIPTrustedProxy 2405:b500::/32
RemoteIPTrustedProxy 2405:8100::/32
RemoteIPTrustedProxy 2a06:98c0::/29
RemoteIPTrustedProxy 2c0f:f248::/32

啟用remoteip.conf

sudo a2enconf remoteip

輸出如下

Enabling conf remoteip.
To activate the new configuration, you need to run:
systemctl reload apache2

測試Apache2設定

sudo apache2ctl configtest

Syntax OK

重啟Apache2

sudo systemctl restart apache2

成功正確取得用戶IP

發佈回覆

你的電郵地址並不會被公開。 必要欄位標記為 *