https://blog.csdn.net/sinat_21302587/article/details/54599135 xxxxxxxxxx location / { root html; index index.html index.htm index index.jpg; auth_basic 'Restricted'; auth_basic_user_file htpasswd; } xhtpasswd -c /usr/local/nginx/conf/htpasswd UserNameUserName 就是你的用户名/usr/local/nginx/conf/htpasswd 是密码文本存放的路径(这跟你的nginx.conf 配置文件中有关)