首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫

Apache 2.x 整合 MySQL 認證模組 mod_auth_mysql 安裝與配置實戰

     編輯:MySQL 資料庫相關知識

背景:降低內部系統暴露風險

公司內部運行 pLog 博客系統,需發布至公網供分支機構使用。為最小化駭客風險,採用外掛 mod_auth_mysql 實現用戶認證,避免直接暴露應用層認證邏輯。

模組版本與來源

SourceForge 專案:https://modauthmysql.sourceforge.net/,版本 2.9.0。文檔殘缺,多版本並存需甄別。

編譯安裝步驟


# 建立目錄並解壓
mkdir mod_auth_mysql && cd mod_auth_mysql
# 編譯
apxs -c -lmysqlclient -lm -lz mod_auth_mysql.c
# 安裝
apxs -i mod_auth_mysql.la

修改 httpd.conf 載入模組:

LoadModule mysql_auth_module modules/mod_auth_mysql.so

配置實戰:整合既有 pLog 用戶表

pLog 用戶表 plog_users,配置如下:




    AuthType Basic
    AuthMySQLHost localhost
    AuthMySQLPort 3306
    AuthMySQLDB plog
    AuthMySQLUser plogdb_user
    AuthMySQLPassword password
    AuthMySQLPwEncryption md5
    AuthMySQLEnable On
    AuthMySQLUserTable plog_users
    AuthMySQLNameField user
    AuthMySQLPasswordField password
    AuthMySQLGroupTable plog_users
    AuthMySQLGroupField user_group


模組對用戶表無特殊要求,只需能找到用戶名/密碼欄位;群組驗證需 user_group 欄位。

資料準備與 .htaccess 保護

公司全體用戶同群組,採群組驗證。在 plog_users 加欄位 user_group,全行更新為固定值 mygroup。若用戶屬多群組需另建群組表。

需保護目錄加 .htaccess:


AuthName "請用管理博客的帳號密碼登入"
AuthType Basic
Require group mygroup

效果與擴展

  • 外掛驗證系統部署完成,對電子商務多應用用戶表整合效果極佳,修改代碼極少
  • 密碼修改可用 PHP $_SERVER["PHP_AUTH_USER"] 判斷用戶名處理
  • Apache 日誌保留瀏覽記錄,配合 AWStats 可分析知識流向
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved