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

时间:2021-01-30 16:53:42

I'm trying to make a directory for my website password protected and I so far I've followed apache instructions to do that: http://httpd.apache.org/docs/current/howto/auth.html

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

and

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

I then created a password file using htpasswd, and then I edited my httpd.conf with

然后我使用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>

But when I go to the website that supposed to ask me for the password it doesn't!

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

I'm just trying to figure out what I'm doing wrong.

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

Thanks!

1 个解决方案

#1


The problem that I didn't think was related to this is that I was trying to access that protected directory using one of my vhosts in the configuration file so I just had to put this Directory directive inside of the correspondig vhost that was getting accessed, this is how I got my configuration at the end:

我认为与此无关的问题是我试图使用配置文件中的一个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>

#1


The problem that I didn't think was related to this is that I was trying to access that protected directory using one of my vhosts in the configuration file so I just had to put this Directory directive inside of the correspondig vhost that was getting accessed, this is how I got my configuration at the end:

我认为与此无关的问题是我试图使用配置文件中的一个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>