【问题标题】:.htpasswd file leads to server error?.htpasswd 文件导致服务器错误?
【发布时间】:2014-06-06 09:39:01
【问题描述】:

.htaccess 文件背后的代码

AuthType Basic  
AuthName "restricted area"  
AuthUserFile ".htpasswd" 
require valid-user

.htpasswd 文件背后的代码

user121:$apr1$bVI1xobF$2ius9YiPaElsFDjD2DK5/0

我使用正确的凭据登录,这是我每次登录时得到的:

Server error!

The server encountered an internal error and was unable to complete your request.
Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.

Error 500

更新

Apache 错误日志:

[Fri Jun 06 20:42:30.503554 2014] [authn_file:error] [pid 7536:tid 1760] (OS 2)
The system cannot find the file specified.  : [client ::1:58747] AH01620: Could
not open password file: C:/xampp/apache/.htpasswd, referer: 
http://localhost/manage/articles/

我无法将文件放在我的虚拟主机上的 xampp/apache 文件夹中?

【问题讨论】:

  • 你的 Apache 错误日志是怎么说的?
  • 我更新了问题!

标签: .htaccess .htpasswd


【解决方案1】:

错误日志显示您使用了错误的 .htpasswd 文件路径:

无法打开密码文件:C:/xampp/apache/.htpasswd

这表明它不在 C:/xampp/apache 中。确保在 .htaccess 文件中使用正确的路径。例如。如果您的 .htpasswd 位于 C:/xampp/apache/htdocs/myproject/.htpasswd 下,请将其设置为这样。

AuthUserFile C:/xampp/apache/htdocs/myproject/.htpasswd

(虽然最好的做法将 .htpasswd 放在您的 htdocs/httpdocs 中,但我只是使用此路径作为示例。)

如果您确定路径正确,因为您似乎是在 Windows 安装上,请确保该文件实际上名为 .htpasswd。 Windows 无法从资源管理器执行此操作(它禁止创建“仅扩展”文件),您必须从基于命令行的工具执行此操作。如果您在记事本等中创建了 .htpasswd,则该文件现在很可能实际上称为 .htpasswd.txt,请使用命令行将其重命名为 .htpasswd:

C:\> cd C:\xampp\apache
C:\xampp\apache> move .htpasswd.txt .htpasswd

【讨论】:

    【解决方案2】:

    我使用的是 Mac,这对我有用:

    /Applications/XAMPP/xamppfiles/bin/htpasswd -cb /Applications/XAMPP/xamppfiles/.htpasswd admin password
    

    【讨论】:

      猜你喜欢
      • 2010-10-07
      • 2014-12-14
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-01
      • 1970-01-01
      相关资源
      最近更新 更多