nginx 设置目录访问权限

1.创建htpasswd文件:

可以使用以下这个python脚本生成认证文件:htpasswd.py

执行命令:

chmod 777 htpasswd.py
./htpasswd.py -c -b filename username password

或安装htpasswd:

apt-get install apache2-utils
htpasswd -c filename username

2.修改nginx的conf

server {
    listen       80;
    
    ***
    ***
    
    auth_basic "Password";
    auth_basic_user_file /var/local/nginx/conf/xxx;

    *** 
    *** 
    }
}

参考资料


阿里云服务器的安全组设置小坑 君子必贵其言 - 《中论》