Apache 特定の仮想パスのみ Basic 認証を設定する

技術情報
公開: 2023年11月16日

関連

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

手順

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

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

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

2. Basic 認証の設定を追加

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

   ・・・
</VirtualHost>

3. apache の再起動

# apachectl configtest
# systemctl restart httpd
# systemctl status httpd