- 生成密码
sudo htpasswd -c /etc/apache2/.htpasswd {username}
- 修改
/etc/apache2/sites-available/{site}.conf
文件,添加:
<Proxy *>
Order deny,allow
Allow from all
Authtype Basic
Authname "Password Required"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Proxy>
3. 重启 Apache 服务 sudo systemctl restart apache2