How to combine basic authentication and https?

I set up a private website that should only be accessible to a few people over the Internet. I would like to set up a combination of basic authentication and https.

So far, everything is working fine if I directly type https://blah.com/location1. However , what I need is to redirect apache http://blah.com/location1to https://blah.com/location1and then perform basic authentication. I do not want basic authentication to be done before the redirect. At the moment, this is what I have in my apache configuration.

WSGIScriptAlias /site /path/to/site/apache/site.wsgi

<Directory /path/to/site/apache>
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
</Directory>

<Location /site>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

    AuthType Basic
    AuthName "Site login"
    AuthUserFile /path/to/site/.htpasswd
    Require valid-user
</Location>

Note. I need authentication only for /site. Therefore, I must have access to http://blah.com/site1, http://blah.com/site2without authentication.

+3
2

, "" HTTP- HTTPS, , HTTP ( URL- HTTPS).

, : HTTP HTTPS.

HTTP , , <Location /location1> ( ).

HTTPS <Location /location1> .

+1

Apache 2.2 SSL *, * auth ( < ?), , SSLRequireSSL, ErrorDocument 403 html 403, JavaScript, HTTPS... , , , VirtualHost HTTP, HTTPS.

0

Source: https://habr.com/ru/post/1774250/


All Articles