公司內部運行 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_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 欄位。
公司全體用戶同群組,採群組驗證。在 plog_users 加欄位 user_group,全行更新為固定值 mygroup。若用戶屬多群組需另建群組表。
需保護目錄加 .htaccess:
AuthName "請用管理博客的帳號密碼登入"
AuthType Basic
Require group mygroup
$_SERVER["PHP_AUTH_USER"] 判斷用戶名處理