1、创建用户名为sam
sh -c “echo -n ‘sam:’ >> /etc/Nginx/.htpasswd”
2、创建用户密码
sh -c “openssl passwd -apr1 >> /etc/nginx/.htpasswd”
3、添加到nginx配置
location / { try_files $uri $uri/ =404; #下列两行为新增 **auth_basic “Restricted Content”; auth_basic_user_file /etc/nginx/.htpasswd;** }