简体   繁体   English

PHP生成的.htpasswd放在哪里?

[英]Where to place .htpasswd generated by PHP?

I am creating a PHP based web application which requires simple authentication to use. 我正在创建一个基于PHP的Web应用程序,该应用程序需要简单的身份验证才能使用。 The application is made to be installed on a web server and used only be the owner of the web hosting/server, so there will only be one user and password. 该应用程序被制成要安装在Web服务器上,并且仅由Web托管/服务器的所有者使用,因此将只有一个用户和密码。 I figured there was no point in creating a complicated login system. 我认为创建复杂的登录系统没有任何意义。 I would just create a GUI to generate .htaccess and .htpasswd files to use Apache's authentication. 我只是创建一个GUI来生成.htaccess和.htpasswd文件以使用Apache的身份验证。 The idea behind it was that it was supposed to simple, however it is turning into more of a job than I anticipated. 它背后的想法是,它本来应该很简单,但是它正在变成比我预期的更多的工作。 I realized I have to place the .htpasswd file somewhere secure, meaning not in a web accessible directory. 我意识到我必须将.htpasswd文件放在安全的位置,这意味着不在Web可访问的目录中。 The problem is that web servers often have different filesystems and permissions, so where can I place it where it will be safe? 问题在于Web服务器通常具有不同的文件系统和权限,因此我可以将其放置在安全的地方? I was able to create a directory with "740" permissions, which should be secure, from what I can tell. 据我所知,我能够创建一个具有“ 740”权限的目录,该目录应该是安全的。 However, this is inconvenient. 但是,这很不方便。 The application really should be limited to one folder, and if necessary a stray .htpasswd file. 该应用程序实际上应仅限于一个文件夹,如有必要,还应使用一个杂散的.htpasswd文件。 I would love to place the .htpasswd in the application folder, but I believe that is not possible if it is secured by the .htaccess file, when I tried it seemed to cause server errors. 我很想将.htpasswd放在应用程序文件夹中,但是我相信如果它由.htaccess文件保护着,那是不可能的,当我尝试它似乎会导致服务器错误时。 If anybody has a solution to that or a better place to put the .htpasswd file it would be greatly appreciated! 如果有人对此有解决方案,或者有更好的放置.htpasswd文件的地方,将不胜感激!

By default apache should be configured not to serve any .ht* files by this rule: 默认情况下,应按以下规则将apache配置为不提供任何.ht*文件:

<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>

So it should be secure to place this file wherever you want. 因此,将文件放置在所需的位置应该是安全的。

If you are encountering server errors check for mod_auth if it is compiled/enabled in apache installation and if your virtual host/webroot has AllowOverride AuthConfig 如果遇到服务器错误,请检查mod_auth是否在apache安装中已编译/启用,以及您的虚拟主机/ webroot是否具有AllowOverride AuthConfig

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

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