当前位置: 首页 > OpenSource > 正文

nginx authentication

今天配置nginx的basic authentication折腾了好半天,开始error_log一直报错:
no user/password was provided for basic authentication

我是按照nginx的wiki配置的:
location  /  {
  auth_basic            “Restricted”;
  auth_basic_user_file  htpasswd;
}

cat htpasswd
2hei:j3M4coizxFLDM

Since version 0.6.7 the filename path is relative to directory of nginx configuration file nginx.conf, but not to nginx prefix directory.

google了半天,发现了nginx作者Igor的一个回复:

Igor Sysoev
The HTTP Basic authentication works as following:
*) A browser requests a page without user/password.
*) A server response with 401 page, sending realm as well.
   At this stage the 401 code appears in access_log and the message
   “no user/password …” appears in error_log.
*) The browser shows a realm/login/password prompt.
*) If a user will press cancel, then the browser will show the received
   401 page.
*) If the user enters login/password, then the browser repeats the request
   with login/password.

Then until you will exit the browser, it will send these login/password
with all requests in protected hierarchy.

赞一个,牛人果然就是牛人!

经过提示找到了罪魁祸首是error_page的配置 401 403 404 /40x.html;

error_page 401 403 404 /40x.html;
实际上是由于40x.html文件并不存在导致的。把文件建好问题得以解决!

本文固定链接: http://2hei.net/nginx_authentication.html | 2hei's site

该日志由 2hei 于2010年01月20日发表在 OpenSource 分类下,
原创文章转载请注明: nginx authentication | 2hei's site
关键字:

报歉!评论已关闭.