关于nginx的auth_basic认证配置

Posted

创建htpasswd文件

sudo htpasswd -c -m conf/htpasswd <user>

如果没有该命令,先安装

sudo apt-get install apache2-utils

```bash nginx.conf server { listen 80; charset UTF-8; server_name domain.com; root /var/www;

location ~/(user|file)/ { auth_basic "Restricted"; auth_basic_user_file conf/htpasswd;
autoindex on; #以索引的方式把文件列出来 }

}


如果报403那么你的auth_basic_user_file就用绝对路径试一试,如:/home/nginx/conf/htpasswd


参考:
[关于autoindex配置说明](/blog/2011/05/22/nginx-configuration-autoindex/)

此文章 短链接: http://dlj.bz/gyS9Fw