简体   繁体   中英

Apache virtual host basic authentication having no effect?

I'm running a VPS with one domain on a virtual host through apache2. I'm trying to set up basic authentication on one of the domains. At the moment I have a .htpasswd file saved in /etc/apache2/.htpasswd . My virtual host is located at /etc/apache2/sites-enabled/example.co.uk.conf and it looks like this:

<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>

The problem is, the authentication doesn't seem to be having any effect. I'm quite new to this and as I understand it this is all I need to add, and it should prompt me for a password when I visit the site, but it has no effect.

Try adding this at the end of your Directory section:

  Order allow,deny
  Allow from all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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