密码保护网站.htaccess和.htpasswd - 错误 - “无法打开密码文件:”

问题描述 投票:1回答:5

我们有Plesk网站建设者通过您的网站托管与宪章。用它来创建一个简单的开发网站。

我正在尝试使用.htaccess / .htpasswd密码保护网站。

无论我做什么,我都会收到这个错误:

[Wed Apr 06 09:02:57 2016] [error] [client 66.169.84.65] (2)No such file or directory: Could not open password file: /.htpasswd
[Wed Apr 06 09:02:57 2016] [error] [client 66.169.84.65] access to / failed, reason: verification of user id 'heather' not configured
[Wed Apr 06 09:03:52 2016] [error] [client 66.169.84.65] (2)No such file or directory: Could not open password file: /etc/httpd/.htpasswd
[Wed Apr 06 09:03:52 2016] [error] [client 66.169.84.65] access to / failed, reason: verification of user id 'admin' not configured
[Wed Apr 06 09:03:56 2016] [error] [client 66.169.84.65] (2)No such file or directory: Could not open password file: /etc/httpd/.htpasswd
[Wed Apr 06 09:03:56 2016] [error] [client 66.169.84.65] access to / failed, reason: verification of user id 'heather' not configured
[Wed Apr 06 09:05:11 2016] [error] [client 66.169.84.65] (2)No such file or directory: Could not open password file: /etc/httpd/HTTP/.htpasswd
[Wed Apr 06 09:05:11 2016] [error] [client 66.169.84.65] access to / failed, reason: verification of user id 'admin' not configured
[Wed Apr 06 09:05:15 2016] [error] [client 66.169.84.65] (2)No such file or directory: Could not open password file: /etc/httpd/HTTP/.htpasswd
[Wed Apr 06 09:05:15 2016] [error] [client 66.169.84.65] access to / failed, reason: verification of user id 'heather' not configured

我对Parallels Plesk并不是很熟悉 - 掌握他们的支持就像拔牙一样。

  • 我检查并仔细检查了.htpasswd文件的路径;似乎是对的。
  • 我已经移动了它和.htaccess文件,看看我是不是在正确的地方没有它

我不确定问题是什么。我收到了验证框(我注意到它没有我的“请登录”消息但是...

enter image description here

这是.htaccess文件的代码:

#
#           AUTHENTICATION
#
### BASIC PASSWORD PROTECTION
AuthUserFile /etc/httpd/HTTP/.htpasswd
AuthName "Please Login"
AuthType basic

<Limit GET POST>
Require valid-user
</Limit>

非常感谢任何帮助或引导正确的方向。提前致谢!!

apache .htaccess password-protection plesk .htpasswd
5个回答
0
投票

我遇到了同样的问题。对我来说,.htpasswd存储在/home/username/.htpasswds目录下。我通过递归确保目录是可执行的来解决错误:

chmod +x -R /home/username/.htpasswds

2
投票

只需通过命令生成/etc/httpd/HTTP/.htpasswd文件:

# htpasswd /etc/httpd/HTTP/.htpasswd UserNameYouWant

它要求您输入密码并使用用户UserNameYouWant生成密码文件


2
投票

你确定文件.htpasswd在/ etc / httpd / HTTP /目录中。否则使用以下命令创建1

sudo htpasswd -c /etc/apache2/.htpasswd heather

Here你去一步一步配置:


0
投票

如果您认为该文件位于正确的位置,则可能是权限问题。

检查文件所有权和权限:

ls -la /path/to/file

确保您的apache进程运行的文件/组能够读取该文件。

您可以通过运行以下方法检查进程的所有者:

ps -ef | grep apache

您应该在最左侧的列中看到该进程的所有者。

如果文件所有权是问题,那么使用chown更改所有权:

sudo chown username: /path/to/file

您需要以root / sudo身份执行此操作,因为非root用户无权正常更改所有权。

:用户名后,将组更改为与用户名相同


0
投票

如果你正在使用CentOS,那么如果文件位于webserver根目录之外,那么SELinux可能阻止访问该文件。 (这就是发生在我身上的事)。

Solution

将文件移动到Web服务器根目录,然后使用以下命令恢复文件SELinux上下文:

mv /path/to/.httpasswd /var/www/html/
restorecon -v /var/www/html/.htpasswd
© www.soinside.com 2019 - 2024. All rights reserved.