Ody*_*3us 15 .htaccess password-protection
我正在尝试密码保护子域及其所有子目录和文件,但我对此事的知识非常有限,我该怎么做呢?
Thanx提前!
Mah*_*esh 22
这是一个简单的两步过程
在你的.htaccess中
AuthType Basic
AuthName "restricted area"
AuthUserFile /path/to/the/directory/you/are/protecting/.htpasswd
require valid-user
Run Code Online (Sandbox Code Playgroud)
使用http://www.htaccesstools.com/htpasswd-generator/或命令行生成密码并将其放入.htpasswd
注意1:如果您使用的是cPanel,则应在安全性部分"密码保护目录"中进行配置
编辑:如果这没有工作,那么propably你需要做AllowOverride All的的.htaccess的目录(或至少到以前的)的http.conf然后是阿帕奇重启
<Directory /path/to/the/directory/of/htaccess>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
</Directory>
Run Code Online (Sandbox Code Playgroud)
        小智 8
要对Apache提供的目录进行密码保护,您需要在要保护的目录中使用.htaccess文件,以及.htpasswd文件,该文件可以是您的系统上Apache用户可以访问的任何位置(但将其放在合理且私密的位置).你很可能不想把它放在.htpasswd同一个文件夹中.htaccess.
.htaccess文件可能已存在.如果没有,请创建它.然后插入:
AuthType Basic
AuthName "Your authorization required message."
AuthUserFile /path/to/.htpasswd
require valid-user
Run Code Online (Sandbox Code Playgroud)
然后使用您想要的任何用户名和密码创建.htpasswd文件.密码应加密.如果您使用的是Linux服务器,则可以使用htpasswd命令为您加密密码.以下是该命令如何用于此:
htpasswd -b /path/to/password/file username password 
只需扩展 Mahesh 的答案。
.htaccessAuthType Basic
AuthName "restricted area"
AuthUserFile /path/to/the/directory/you/are/protecting/.htpasswd
require valid-user
Run Code Online (Sandbox Code Playgroud)
如果您不想使用在线密码生成器,您可以使用htpasswd或openssl:
htpasswdAuthType Basic
AuthName "restricted area"
AuthUserFile /path/to/the/directory/you/are/protecting/.htpasswd
require valid-user
Run Code Online (Sandbox Code Playgroud)
opensslopenssl passwd -apr1 your_password
Run Code Online (Sandbox Code Playgroud)
然后把生成的密码改成.htpasswdwith 格式:
username:<generated_password>
Run Code Online (Sandbox Code Playgroud)
例子:
.htpasswdmy_username:$apr1$ydbofBYx$6Zwbml/Poyb61IrWt6cxu0
Run Code Online (Sandbox Code Playgroud)