php 401认证,给phpMyAdmin增加401加密认证
phpMyAdmin是一個以PHP為基礎,以Web-Base方式架構在網站主機上的MySQL的數據庫管理工具,讓管理者可用Web接口管理MySQL數據庫。由于phpMyAdmin漏洞比較多,所以我們除了要更改默認路徑外還要設置401驗證,提高安全性,不過還是不建議安裝phpMyAdmin,畢竟漏洞確實多。
安裝apache htpasswd命令
yum -y install httpd-tools
1
yum-yinstallhttpd-tools
首先通過htpasswd生成401的帳號和密碼,此處采用SHA加密
htpasswd -cs /usr/local/nginx/conf/401htpasswd whsir #whsir為401用戶名
1
htpasswd-cs/usr/local/nginx/conf/401htpasswdwhsir#whsir為401用戶名
將401添加到php的location中
location ~ \.php$ {
auth_basic "this is 401whsir";
auth_basic_user_file /usr/local/nginx/conf/401htpasswd;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
1
2
3
4
5
6
7
8
location~\.php${
auth_basic"this is 401whsir";
auth_basic_user_file/usr/local/nginx/conf/401htpasswd;
fastcgi_passunix:/tmp/php-cgi.sock;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi.conf;
}
檢查配置
nginx -t
1
nginx-t
重啟nginx
service nginx restart
1
servicenginxrestart
假設phpmyadmin地址是http://10.10.10:888/phpmyadmin/
此時訪問http://10.10.10:888/phpmyadmin/就會跳出401了
如果按下面這種方法配置的話,使用絕對路徑是可以繞過401的
location /
{
auth_basic "this is 401whsir";
auth_basic_user_file /usr/local/nginx/conf/401htpasswd;
}
1
2
3
4
5
location/
{
auth_basic"this is 401whsir";
auth_basic_user_file/usr/local/nginx/conf/401htpasswd;
}
舉例:正常訪問http://10.10.10:888/phpmyadmin/跳出401
如果訪問http://10.10.10:888/phpmyadmin/index.php,取消多次是可以繞過401的,這里假設目錄下有index.php文件
給帝國后臺增加401認證,示例如下:
location /e/admin/
{
auth_basic "401";
auth_basic_user_file /usr/local/nginx/conf/401htpasswd;
}
location ~ /e/admin/.*\.php$
{
auth_basic "401";
auth_basic_user_file /usr/local/nginx/conf/401htpasswd;
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
location/e/admin/
{
auth_basic"401";
auth_basic_user_file/usr/local/nginx/conf/401htpasswd;
}
location~/e/admin/.*\.php$
{
auth_basic"401";
auth_basic_user_file/usr/local/nginx/conf/401htpasswd;
try_files$uri=404;
fastcgi_passunix:/tmp/php-cgi.sock;
fastcgi_indexindex.php;
includefastcgi.conf;
}
注意:上面配置要放在location ~ [^/]\.php(/|$)的前面
htpasswd命令常用的幾個選項:
-c:創建一個加密文件
-p:不對密碼進行進行加密,即明文密碼
-m:采用MD5算法對密碼進行加密
htpasswd -c -s /usr/local/nginx/conf/401 whsir
-d:采用CRYPT算法對密碼進行加密
htpasswd -c -s /usr/local/nginx/conf/401 whsir
-s:采用SHA算法對密碼進行加密
htpasswd -c -s /usr/local/nginx/conf/401 whsir #用戶名whsir
-b:在命令行中一并輸入用戶名和密碼而不是根據提示輸入密碼
htpasswd -c -b /usr/local/nginx/conf/401 whsir 123 #用戶名whsir,密碼123
~微信打賞~
賞
分享到:
總結
以上是生活随笔為你收集整理的php 401认证,给phpMyAdmin增加401加密认证的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信小程序:蓝牙通讯,搜索、发送与接收
- 下一篇: Ubuntu中挂载使用nas服务器