简体   繁体   English

htaccess文件引用转到/ etc / apache2,尝试将其更改为相对

[英]htaccess file references going to /etc/apache2, trying to change to relative

I have the following in my .htaccess file: 我的.htaccess文件中包含以下内容:

AuthType Basic
AuthName "Secured"
AuthUserFile ../private/passwd
Require valid-user
Order allow,deny
Allow from env=unauthenticated
Satisfy any

The problem from the error.log is that Apache is saying "Could not open password file: /etc/apache2/passwd" - which is obviously my Apache root. error.log的问题是Apache在说“无法打开密码文件:/ etc / apache2 / passwd”,这显然是我的Apache根目录。

How would I specify a relative reference to the .htaccess file for a path instead? 如何为路径指定对.htaccess文件的相对引用?

And probably very important, can this be done in the .htaccess file only? 可能非常重要,这只能在.htaccess文件中完成吗?

If so, answering question #2 would make the solution much more portable. 如果是这样,回答问题2将使解决方案更加可移植。

Doc: AuthUserFile Doc: AuthUserFile

The AuthUserFile directive sets the name of a textual file containing the list of users and passwords for user authentication. AuthUserFile指令设置文本文件的名称,该文本文件包含用户列表和用于用户认证的密码。 File-path is the path to the user file. File-path是用户文件的路径。 If it is not absolute, it is treated as relative to the ServerRoot. 如果不是绝对的,则将其视为相对于ServerRoot的。

So I assume that your server root is in /etc/apache2/ so your relative URL: ./passwd will be relative to the root, and not where your htaccess file is at. 因此,我假设您的服务器根目录位于/etc/apache2/因此您的相对URL: ./passwd将相对于根目录,而不是 htaccess文件所在的位置。 Thus, it's not possible to make it portable and relative to where you place the htaccess. 因此,不可能使其相对于htaccess放置在便携式位置。

Additionally, the documentation also says: 此外,文档还说:

Security 安全

Make sure that the AuthUserFile is stored outside the document tree of the web-server. 确保AuthUserFile存储在Web服务器的文档树之外。 Do not put it in the directory that it protects. 不要将其放在其保护的目录中。 Otherwise, clients may be able to download the AuthUserFile. 否则,客户端可能能够下载AuthUserFile。

So it's a bad idea to keep your password file in the same place that you serve your content. 因此,将密码文件保存在提供内容的位置上是一个坏主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM