nginx可以实现如下图所示的功能
- 通过命令生成passfile文件
htpasswd -c -d /path/to/pass_file username
//回车后输入密码,再次回车后,输入确认密码
//操作结束后看看passfile文件是否生成
- 修改ngnix的配置文件
location ~ /test {
auth_basic "Restricted";
auth_basic_user_file /path/to/pass_file; //使用绝对路径
root /path/to/your/webroot; //网站根目录
}
- 重启nginx