Apache虚拟主机基本身份验证没有效果?

时间:2017-03-25 15:11:48

标签: linux apache ubuntu virtualhost vps

我通过apache2在虚拟主机上运行一个带有一个域的VPS。我试图在其中一个域上设置基本身份验证。目前,我在/etc/apache2/.htpasswd中保存了.htpasswd文件。我的虚拟主机位于/etc/apache2/sites-enabled/example.co.uk.conf,看起来像这样:

<VirtualHost *:80>
    ServerName example.co.uk
    ServerAlias www.example.co.uk
    DocumentRoot /var/www/example.co.uk/public_html

    <Directory /var/www/example.co.uk/public_html>
            AuthType Basic
            AuthBasicProvider file
            AuthName "Restricted Files"
            AuthUserFile /etc/apache2/.htpasswd
            require valid-user
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =www.example.co.uk [OR]
    RewriteCond %{SERVER_NAME} =example.co.uk
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

问题是,身份验证似乎没有任何效果。我对此非常陌生,据我所知,这是我需要添加的全部内容,当我访问该网站时它应该提示我输入密码,但它没有效果。

1 个答案:

答案 0 :(得分:0)

尝试在Directory部分的末尾添加此内容:

  Order allow,deny
  Allow from all