天天看點

Nginx auth_basic+phpMyAdmin安全驗證

phpMyAdmin 是一個以 PHP 為基礎,以 Web-Base 方式架構在網站主機上的 MySQL 的資料庫管理工具,讓管理者可用 Web 接口管理 MySQL 資料庫。

通過 Nginx auth_basic 驗證功能,可以為 phpMyAdmin 目錄增加使用者名,密碼驗證機制。防止任意使用者通路 phpMyAdmin(0day 我怕怕!)。

一,使用 htpasswd 指令生成密碼檔案,支援文法如下:

/usr/bin/htpasswd -c passwordfile username      

二,舉例:生成一個 reistlin.passwd 密碼檔案,使用者名 admin,密碼 ***

/usr/bin/htpasswd -c /etc/nginx/conf/reistlin.passwd admin

New password: ***
Re-type new password: ***

Adding password for user admin

# 注意,密碼檔案通路權限
chmod 600 reistlin.passwd      

三,編輯 nginx.conf,配置 auth_basic,配置 reistlin.passwd 密碼檔案路徑,配置通路政策和請求限制

# http
limit_req_zone  $binary_remote_addr  zone=admin:1m  rate=3r/m;

# location
location /phpMyAdmin/ {
        root   /home/reistlin/htdocs;
        index  index.html  index.htm  index.php;
        auth_basic  "Administrator Login";
        auth_basic_user_file  /etc/nginx/conf/reistlin.passwd;

        limit_req  zone=admin  burst=3;
}      

四,驗證配置檔案,Reload Nginx 配置

/etc/nginx/sbin/nginx -t

the configuration file /etc/nginx/conf/nginx.conf syntax is ok
configuration file /etc/nginx/conf/nginx.conf test is successful

kill -HUP `cat /etc/nginx/logs/nginx.pid`      

猜你喜歡:

繼續閱讀