以 phpMyAdmin 网站为例
将 phpMyAdmin 隐藏在认证代理后面,这样用户在向 phpMyAdmin 提供 MySQL 凭证之前就需要进行认证
官方文档
AuthBasicProvider Directive
使用 htpasswd 创建密码文件
htpasswd -c /usr/share/phpmyadmin/passwd test01
New password: Re-type new password: Adding password for user test01
cat /usr/share/phpmyadmin/passwd
test01:$apr1$SUzFEIsh$ZYz1pDpxTuaqxORN8oYem0
如果需要修改密码,先使用 htpasswd -D 删除,再使用 htpasswd -b修改
htpasswd -D /usr/share/phpmyadmin/passwd test01
Deleting password for user test01
htpasswd -b /usr/share/phpmyadmin/passwd test01 123456
Adding password for user test01
配置需要代理的网站
cd /etc/httpd/conf.d
cat phpmyadmin.conf
## Possible values for the Options directive are "None", "All",# or any combination of:# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews## Note that "MultiViews" must be named *explicitly* --- "Options All"# doesn't give it to you.## The Options directive is both complicated and important. Please see# http://httpd.apache.org/docs/2.4/mod/core.html#options# for more information.## wzh 20230313Options Indexes FollowSymLinks# Options -Indexes +FollowSymLinks## AllowOverride controls what directives may be placed in .htaccess files.# It can be "All", "None", or any combination of the keywords:# Options FileInfo AuthConfig Limit## wzh 20230313#AllowOverride None#AllowOverride All## Controls who can get stuff from this server.## Require all granted# wzh 20230314AuthType BasicAuthName "Restricted Access"AuthUserFile /usr/share/phpmyadmin/passwdRequire valid-user Alias /phpadmin /var/www/html/phpmyadmin
重启 apache 服务
systemctl restart httpd
ubuntu 系统
systemctl status apache2
测试 http://192.168.0.113/phpmyadmin