nginx和auth_basic [英] nginx and auth_basic

查看:84
本文介绍了nginx和auth_basic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Ubuntu Jaunty中使用nginx进行基本身份验证.在nginx.conf中,我在服务器上下文下添加了这两行:

I am trying to get basic authentication working with nginx in Ubuntu Jaunty. In nginx.conf, I added these two lines under the server context:

server {
   ...
   auth_basic "Restricted Access";
   auth_basic_user_file /etc/nginx/.htpasswd;
   ...
}

然后我轻松获得apache2-utils以获取htpasswd,我曾用它来创建htpasswd文件:

Then I apt-get'ed apache2-utils to get htpasswd, which I used to create the htpasswd file:

htpasswd -d -c /etc/nginx/.htpasswd joe

当我尝试访问该站点时,将出现预期的身份验证对话框,但是当我输入用户名和密码时,它只是刷新了对话框.它似乎不喜欢我提供的密码.我尝试同时使用htpasswd和不使用-d选项,但还是没有运气.它拒绝认证.有什么想法我做错了吗?

When I try to access the site, the authentication dialog comes up as expected, but when I put in the username and password, it just refreshed the dialog box. It doesn't seem to like the password I am providing it. I tried running htpasswd both with and without the -d option, but still no luck. It refused to authenticate. Any ideas what I'm doing wrong?

任何帮助将不胜感激.

推荐答案

我要检查的内容:

  • /etc/nginx/.htpasswd上的权限-运行nginx的帐户可以读取该文件吗?您可以暂时尝试使用"chmod 644"来确保每个人都可以阅读.如果可行,那么您可以对"chown"和"chmod"设置进行适当的组合,以便nginx和您(或root)可以读取它,但其他用户则不能读取(出于安全性考虑).
  • 确保htpasswd以正确的格式生成哈希;通常是大约13个字母数字字符(例如`username:wu.miGq/e3nro`).该命令也可以生成MD5散列,看起来更像是`username:$ apr1 $ hzB2K ... $ b87zlCYMKufOxn9ol5QV4/`,这些散列不适用于nginx.
  • 考虑增加nginx的调试输出,并检查错误日志中的线索.

这篇关于nginx和auth_basic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆