Loading... ## 创建密码文件 ```bash mkdir -p /usr/local/nginx/conf/pw/ touch /usr/local/nginx/conf/pw/pr.htpasswd chown www:www /usr/local/nginx/conf/pw/ -R ``` ## 生成密码 ```bash # 安装htpasswd sudo apt-get install apache2-utils # 生成密码 htpasswd -c -d /usr/local/nginx/conf/pw/pr.htpasswd proqwertyuiop New password: Re-type new password: Adding password for user proqwertyuiop # 查看文件内容 cat /usr/local/nginx/conf/pw/pr.htpasswd proqwertyuiop:6hrfDkASkpYac ``` ## 在 Nginx 中配置 Auth Basic ```bash location /test { auth_basic "请输入账号密码"; auth_basic_user_file /usr/local/nginx/conf/pw/pr.htpasswd; } ``` ## 重载 Nginx 配置 ```bash service nginx reload ``` 最后修改:2024 年 03 月 05 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏