针对sudo apt-get install命令安装的Nginx(默认会有/etc/Nginx/conf.d)
sudo apt-get install Nginx
生成密码
printf "your_username:$(openssl passwd -crypt your_password)\n" >> conf.d/passwd
如果没有conf.d/passwd这个文件,就自行创建
配置Nginx
vim /etc/Nginx/sites-enabled/default
location / { auth_basic 网站名称"; auth_basic_user_file conf.d/passwd; autoindex on; }
重启Nginx
/etc/init.d/Nginx restart
访问效果如下