针对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

访问效果如下

为 Nginx 添加 HTTP 基本认证(HTTP Basic Authentication)

 

相关文章:

  • 2022-01-09
  • 2021-04-06
  • 2021-08-29
  • 2021-06-11
  • 2021-10-18
  • 2021-10-19
猜你喜欢
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2021-06-22
相关资源
相似解决方案