简单实现 nginx 用户登录认证

1. 安装 htpasswd 工具

yum -y install httpd-tools  

2. 创建认证用户

htpasswd -c pass.db wang  //wang 并输入密码

在次添加用户时输入时输入

htpasswd pass.db username

会在/etx/nginx/passwd.db文件中生成用户名和加密的密码:
myuser:YlmaHlkJnzhxG

3.nginx 增加两项配置:

增加 auth_basic 和 auth_basic_user_file

 vim /usr/local/nginx/conf/nginx.conf

server {
    listen       80;
    server_name  local.server.com;
    
    **auth_basic "User Authentication";
    auth_basic_user_file /etc/nginx/pass.db;**
    
    location / {
        root   /data/www;
        index  index.html;
    }
}

4 . 重启nginx服务

nginx -s reload

登录页面的时候就会显示输入用户名密码
file
点击该链接,获取博客解锁验证码

猜你喜欢

转载自www.cnblogs.com/lixiaobao/p/11794164.html
今日推荐