Skip to content

Nuface Blog

隨意隨手記 Casual Notes

Menu
  • Home
  • About
  • Services
  • Blog
  • Contact
  • Privacy Policy
  • Login
Menu

OPNsense 反向代理登入錯誤:「The HTTP_REFERER does not match…」解決教學

Posted on 2025-11-102025-11-10 by Rico

在企業或實驗室網路中,我們常希望透過 Apache 反向代理(Reverse Proxy) 來統一內部系統的存取網址,例如:

https://opnsense.demo.com/

然而,當 OPNsense 的管理介面被反向代理後,登入時可能會出現以下錯誤訊息:

The HTTP_REFERER "https://opnsense.demo.com/" does not match the predefined settings.
You can disable this check if needed under System: Settings: Administration.

🧩 問題原因

這個錯誤與 OPNsense 的 CSRF(跨站請求偽造防護) 機制有關。
OPNsense 會比對登入請求的 HTTP_REFERER 是否與系統設定的主機名稱相符。

當你透過反向代理使用 https://opnsense.demo.com/ 存取時,實際上後端看到的 Host 名稱可能不同(例如 10.0.0.1 或 firewall.localdomain),導致比對失敗而出錯。


✅ 解決方案一:暫時停用檢查(快速但不建議長期使用)

  1. 以原始 IP 登入 OPNsense(例如 https://10.0.0.1/)
  2. 前往 System → Settings → Administration
  3. 勾選「Disable HTTP_REFERER check」
  4. 儲存設定後即可透過反向代理登入

⚠️ 安全性較低,僅建議在完全內網的環境暫時使用。


✅ 解決方案二(推薦):修改主機名稱設定

這是最乾淨、長期穩定的做法。

  1. 前往 System → Settings → General
    • Hostname:opnsense
    • Domain:demo.com
  2. 前往 System → Settings → Administration
    • 在「Alternate hostnames」中加入 opnsense.demo.com
  3. 儲存並重新登入

現在 OPNsense 會視 opnsense.demo.com 為合法的登入來源,Referer 檢查自然通過。


🧱 Apache 反向代理設定範例

以下為 /etc/apache2/sites-available/opnsense.conf 範例:

<VirtualHost *:443>
    ServerName opnsense.demo.com

    SSLEngine on
    SSLCertificateFile      /etc/letsencrypt/live/opnsense.demo.com/fullchain.pem
    SSLCertificateKeyFile   /etc/letsencrypt/live/opnsense.demo.com/privkey.pem

    ProxyPreserveHost On
    SSLProxyEngine on
    SSLProxyVerify none
    SSLProxyCheckPeerName off
    SSLProxyCheckPeerExpire off

    ProxyPass        / https://10.0.0.1/
    ProxyPassReverse / https://10.0.0.1/

    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-For %{REMOTE_ADDR}s
    RequestHeader set X-Forwarded-Host %{HTTP_HOST}s

    # (可選)WebSocket 轉發
    ProxyPass        /ws wss://10.0.0.1/ws
    ProxyPassReverse /ws wss://10.0.0.1/ws

    ErrorLog  ${APACHE_LOG_DIR}/opnsense_error.log
    CustomLog ${APACHE_LOG_DIR}/opnsense_access.log combined
</VirtualHost>

🔐 安全建議

  • 限制管理介面可訪問的來源 IP
  • 啟用 2FA(TOTP)
  • 使用合法憑證(建議整合 ACME 自動更新)
  • 確保 WebSocket /ws 正常代理

📘 結論

這個問題常見於使用反向代理整合 OPNsense 的環境。
只要在 OPNsense 的「主機名稱」與「Alternate hostnames」設定正確,即可兼顧安全性與便利性,不必關閉 Referer 檢查,也能穩定透過自訂域名登入防火牆介面。

Recent Posts

  • Postfix + Let’s Encrypt + BIND9 + DANE Fully Automated TLSA Update Guide
  • Postfix + Let’s Encrypt + BIND9 + DANE TLSA 指紋自動更新完整教學
  • Deploying DANE in Postfix
  • 如何在 Postfix 中部署 DANE
  • DANE: DNSSEC-Based TLS Protection

Recent Comments

  1. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on High Availability Architecture, Failover, GeoDNS, Monitoring, and Email Abuse Automation (SOAR)
  2. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on MariaDB + PostfixAdmin: The Core of Virtual Domain & Mailbox Management
  3. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on Daily Operations, Monitoring, and Performance Tuning for an Enterprise Mail System
  4. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on Final Chapter: Complete Troubleshooting Guide & Frequently Asked Questions (FAQ)
  5. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on Network Architecture, DNS Configuration, TLS Design, and Postfix/Dovecot SNI Explained

Archives

  • December 2025
  • November 2025
  • October 2025

Categories

  • AI
  • Apache
  • Cybersecurity
  • Database
  • DNS
  • Docker
  • Fail2Ban
  • FileSystem
  • Firewall
  • Linux
  • LLM
  • Mail
  • N8N
  • OpenLdap
  • OPNsense
  • PHP
  • QoS
  • Samba
  • Switch
  • Virtualization
  • VPN
  • WordPress
© 2025 Nuface Blog | Powered by Superbs Personal Blog theme