配置nginx身份验证(ngx_http_auth_basic_module)

编译的时候默认参数即可

./configure --with-pcre=../pcre --with-zlib=../zlib --with-http_ssl_module --with-openssl=../openssl --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_flv_module --with-debug

 

修改配置文件

location / {
            root   
/usr/local/nginx/html;
                auth_basic 
"Auth";
                 auth_basic_user_file 
/usr/local/nginx/conf/htpasswd; 
            index  index.html index.htm;
}

 

auth_basic "Auth"中的Auth是弹出框(输入用户名和密码)的标题

auth_basic_user_file /usr/local/nginx/conf/htpasswd; 中的/usr/local/nginx/conf/htpasswd是保存密码的文件

密码文件生成,需要apt-get install mini-httpd

htpasswd -/usr/local/nginx/conf/htpasswd 用户名

 

配置好后,重启,应该就可以了。

注:我在配置的时候,由于IE9缓存数据,造成不弹出身份验证框。清楚缓存就好了。 

 

posted on 2010-12-14 15:37  s3  阅读(1529)  评论(0编辑  收藏  举报