Apache 使用.htaccess和.htpasswd密码保护网站-错误-“;无法打开密码文件:";

Apache 使用.htaccess和.htpasswd密码保护网站-错误-“;无法打开密码文件:";,apache,.htaccess,password-protection,plesk,.htpasswd,Apache,.htaccess,Password Protection,Plesk,.htpasswd,我们有普莱斯克网站建设者通过我们的网站托管与宪章。使用它创建一个简单的开发网站 我正在尝试使用.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]

我们有普莱斯克网站建设者通过我们的网站托管与宪章。使用它创建一个简单的开发网站

我正在尝试使用.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
我对平行蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇形蛇

  • 我已经检查并再次检查了.htpasswd文件的路径;似乎是对的
  • 我已经移动了它和.htaccess文件,看看我是否 没有放在正确的地方
我不确定是什么问题。我得到了身份验证框(我注意到它没有我的“请登录”消息,虽然

以下是.htaccess文件的代码:

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

<Limit GET POST>
Require valid-user
</Limit>
#
#认证
#
###基本密码保护
AuthUserFile/etc/httpd/HTTP/.htpasswd
AuthName“请登录”
AuthType basic
需要有效用户

非常感谢您提供的任何帮助,我们将为您指引正确的方向。请提前感谢!!

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

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

它要求您输入密码并生成用户用户名为youwant的密码文件

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

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

您可以逐步进行配置:

如果您认为文件位置正确,可能是权限问题

使用以下选项检查文件所有权和权限:

ls -la /path/to/file
确保apache进程运行的文件/组能够读取该文件

您可以通过运行以下命令来检查进程的所有者:

ps -ef | grep apache
您应该在最左边的列中看到进程的所有者

如果存在文件所有权问题,请使用chown更改所有权:

sudo chown username: /path/to/file
您需要以root/sudo身份执行此操作,因为非root用户通常无权更改所有权


:在用户名更改为与用户名相同后,我遇到了相同的问题。对我来说,
.htpasswd
存储在
/home/username/.htpasswds
目录下。我通过递归确保目录可执行来解决错误:

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

如果您使用的是
CentOS
,那么如果文件位于webserver根目录之外,则可能
SELinux
会阻止对该文件的访问。(我就是这样做的)

解决方案 将文件移动到web服务器根目录,然后使用以下命令还原文件
SELinux
上下文:

mv/path/to/.httpasswd/var/www/html/
restorecon-v/var/www/html/.htpasswd

我在Rackspeed服务器上也遇到了同样的问题。这是因为
/home/company/.htpasswds/project/

中缺少文件
passwd
。此解决方案是安全的?没有副作用?这也会使文件可执行,这是不可取的。