简体   繁体   中英

How to password protect Laravel site within apache vhost?

I am trying to password protected my Laravel application with Apache vhost file. It asks for my username and password but it keeps asking this for every route and every time I reload the page.

Can somebody please explain me how do I need to change the config file in order for the site to ask password and username only once?

This is the directory part of my vhost file:

    ServerAdmin admin@mysite.com
    ServerName staging.app.mysite.ee
    ServerAlias www.staging.app.mysite.ee
    DocumentRoot /var/www/mysite/app/staging/public

    <Directory "/var/www/mysite/app/staging">
            Options +FollowSymLinks +MultiViews +Indexes
            AllowOverride All
            Order allow,deny
            Allow from all

            #AuthType Basic
            #AuthName "Restricted Area"
            #AuthUserFile /var/www/.htpasswd
            #Require valid-user
    </Directory>

You can put below code in either .htaccess file in document root of your project. Or you can add below code in apache configuration file.

AuthName "Dialog prompt"
AuthType Basic
AuthUserFile FULL_PATH_OF_FILE_HTPASSWD
Require valid-user

.htpasswd file should contain username and password.

Username:HASHED_PASSWORD

This will prompt password only once ie. will be set in session.

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