LoginSignup
12
17

More than 5 years have passed since last update.

[Apache][小ネタ] 特定のURLのみ、Basic認証を外す

Posted at

今回はApacheの小ネタを紹介します。

特定のURLのみ、認証なしでアクセスを許可したい

httpd.confを編集する

httpd.conf
# サイト全体にベーシック認証を設定
# ユーザーやパスワードは適宜変更
<Location />
  AuthType Basic
  AuthName "hogehoge"
  AuthName "id and password?"
  AuthUserFile /etc/httpd/.htpasswd
  Require valid-user
</Location>

# jpeg、pngとgif画像については、認証なしでアクセスを許可する
<LocationMatch /.+\.(jpe?g|png|gif)$> 
  Order allow,deny
  Allow from all
  Satisfy Any
</LocationMatch>

ちょっと解説

「Satisfy Any」を設定すると、認証されたユーザーもしくは、
IPのどちらかで許可されれば、アクセスが可能になります。
今回は、画像系の拡張子がついたURLを全て許可するようにしました。

「Satisfy All」だと、両方の許可が必要なようです。

12
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
17