nginx-增加访问身份验证

2021-09-01  本文已影响0人  李哈哈_2c85
1、安装httpd工具

需要使用htpassword命令来配置访问的密码。此命令是httpd-tools程序包的一部分,因此第一步是安装该程序包。

yum install -y httpd-tools
2、设置HTTP基本身份验证凭据

该密码和关联的用户名将存储在您指定的文件中。密码将被加密,文件名可以是您喜欢的任何名称。在这里,我们使用文件/etc/nginx/.htpasswd和用户名nginx。

htpasswd -c /usr/local/nginx/conf/.htpasswd nginx
New password: 输入密码
Re-type new password: 确认密码
Adding password for user nginx
#添加用户命令
htpasswd -b /etc/nginx/conf.d/.htpasswd user1 passwd1
3、更新Nginx配置

两个参数auth_basic和auth_basic_user_file(这两个参数可以配置段: http, server, location, limit_except
auth_basic 将在身份验证提示下显示; value auth_basic_user_file是在步骤2中创建的密码文件的路径

vim dstool.pri.sinohorizon.cn.conf
auth_basic "authentication";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
4、重新加载nginx,测试验证
nginx -s reload
访问测试

参考文章:https://cloud.tencent.com/developer/article/1355807

上一篇 下一篇

猜你喜欢

热点阅读