Configure Basic Authentication for specific virtual paths only on Apache.

Tech Knowledge
Published on November 16, 2023

関連

Apache 2.4.x Basic 認証
Apache 特定の仮想パスのみ Basic 認証を除外する

手順

前提:Basic 認証の有効化を行っていること

1パスワードファイルの作成

# mkdir /var/aworker/auth
# htpasswd -c /var/hoge/auth/.htpasswd user
hoge

2Basic 認証の設定を追加

aworker.conf
<VirtualHost *:80>
   <Location /admin>
      AuthType Basic
      AuthName "Basic Auth"
      AuthUserFile /var/hoge/auth/.htpasswd
      Require valid-user   
   </Location>

   ・・・
</VirtualHost>

3apache の再起動

# apachectl configtest
# systemctl restart httpd
# systemctl status httpd