密码使用基本身份验证保护目录

时间:2015-05-08 22:02:20

标签: apache .htaccess authentication httpd.conf

我正在尝试为我的网站密码保护目录,我到目前为止我已经按照apache说明执行此操作:http://httpd.apache.org/docs/current/howto/auth.html

http://wiki.apache.org/httpd/PasswordBasicAuth

然后我使用htpasswd创建了一个密码文件,然后用

编辑了我的httpd.conf
<Directory /var/www/html/project/app.project.com/Admin/>
AuthType Basic
AuthName "Restricted Area"
# (Following line optional)
AuthBasicProvider file
AuthUserFile "/var/www/html/admin/.password"
Require valid-user

Order allow,deny
Allow from all
</Directory>

但是当我去那个应该问我密码的网站时,它没有!

我只想弄清楚我做错了什么。

谢谢!

1 个答案:

答案 0 :(得分:0)

我没想到与此有关的问题是我试图使用配置文件中的一个vhost来访问该受保护的目录,因此我只需将此Directory指令放在对应的vhost中。获取访问权限,这就是我最终获得配置的方式:

# Please note as well that I'm forcing connections from http to https:

<VirtualHost *:80>
ServerName app.project.com
ServerAlias project.com
DocumentRoot /var/www/html/project/app.project.com

Redirect permanent / https://app.project.com

ErrorLog /var/www/html/project/app.project.com/error.log
CustomLog /var/www/html/project/app.project.com/requests.log combined
</VirtualHost>


 <VirtualHost *:443>
 ServerName app.project.com
 DocumentRoot /var/www/html/project/app.project.com
 SSLEngine On
 SSLCertificateFile /etc/httpd/ssl/40d5d69ae6a53.crt
 SSLCertificateKeyFile /etc/httpd/ssl/project.key
 SSLCertificateChainFile /etc/httpd/ssl/gd_bundle-g2-g1.crt

#Adding the Directory directive to request auth access with password to the Admin directory 

<Directory /var/www/html/project/app.project.com/Admin/>
AuthType Basic
AuthName "Restricted Area"
# (Following line optional)
AuthBasicProvider file
AuthUserFile "/var/www/html/admin/.password"
Require valid-user

Order allow,deny
Allow from all
</Directory>
</VirtualHost>