在本地主机上使用密码保护文件夹的密码失败(在Apache和Windows下) [英] Protect folder with password fails on localhost (under Apache and Windows)

查看:98
本文介绍了在本地主机上使用密码保护文件夹的密码失败(在Apache和Windows下)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保护文件夹,以防止在Windows计算机上的Apache Web服务器下的本地主机上使用用户名和密码直接访问文件夹.根据此文章,我在phpinfo结果中寻找了DOCUMENT_ROOT值并找到以下内容:C:/Program Files/Apache Software Foundation/Apache2.2/htdocs.

I am trying to protect a folder from direct access with username and password on localhost under Apache webserver on Windows machine. According to this article, I've looked for DOCUMENT_ROOT value in phpinfo results and found the following: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs.

由于我在htdocs中的文件夹称为protected,因此我创建了以下htaccess文件:

Since my folder inside htdocs is called protected, I created the following htaccess file:

AuthType Basic
AuthName "restricted area"
AuthUserFile C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/protected/.htpasswd
require valid-user

和以下.htpasswd(用户:test,密码:test)

and the following .htpasswd (user:test, password: test)

test:teH0wLIpW0gyQ

但是当我尝试访问该文件夹时,出现内部服务器错误".查看Apache错误日志,发现以下行:

But when I try to access the folder, I receive an "Internal Server Error". Looking on Apache error log, I found the following line:

[Thu Mar 13 22:00:15 2014] [alert] [client 127.0.0.1] C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/protected/.htaccess: AuthUserFile takes 1-2 arguments, text file containing user IDs and passwords

我想念什么?我似乎与.htpasswd路径中的空格无关,但与.htpasswd sintax有关.我想构建一些可以在本地主机和在线上使用的东西.

What am I missing? I doesn't seem to be related to spaces in .htpasswd path, but something related to .htpasswd sintax. I would like to build something which can be used both on localhost and online.

更新

将htpasswd路径包含在逗号中间可以消除错误

Enclosing htpasswd path into inverted commas eliminates the error

AuthUserFile "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/protected/.htpasswd"

,但不幸的是无法正常工作(如果在需要时输入user:test,password:test,则会收到密码不匹配错误).请参阅以下Apache日志:

but unfortunately doesn't work (if I type user:test, password:test when required I receive a password mismatch error). See the following apache log:

[Thu Mar 13 22:26:43 2014] [error] [client 127.0.0.1] user test: authentication failure for "/protected/": Password Mismatch

有什么想法吗?

推荐答案

已解决!这里是在Windows下配置Apache以使用密码保护文件夹的步骤(在此示例中,我使用"protected"作为文件夹名称,使用"htdocs"作为位置,但是您可以根据需要更改它们):

Solved! Here the steps to configure Apache under windows to protect a folder with password (in this example I use "protected" as folder name and "htdocs" as location, but you can change them as you want):

  • 在"htdocs"下创建受保护"文件夹
  • 在受保护"中创建包含以下代码的.htaccess文件
  • 转到此密码生成器工具并创建您的用户名和密码
  • 将获得的代码粘贴到.htpasswd文件中,并将其放在受保护的"文件夹中
  • 创建一个index.html文件并将其放在受保护"文件夹中
  • 在浏览器上转到http://localhost/protected/
  • 输入您选择的用户名和密码
  • create folder "protected" under "htdocs"
  • create .htaccess file inside "protected" containing the code below
  • go to this password generator tool and create your user and password
  • paste the obtained code to a .htpasswd file and put it inside "protected" folder
  • create a index.html file and put it inside "protected" folder
  • on your browser go to http://localhost/protected/
  • type username and password you've chosen

.htaccess

AuthType Basic
AuthName "restricted area"
AuthUserFile "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/protected/.htpasswd"
require valid-user

希望它对某人有帮助.

这篇关于在本地主机上使用密码保护文件夹的密码失败(在Apache和Windows下)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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