特定のアドレスからのリクエストの場合、基本認証をスキップする
Apache2.4で運営しているサイトがありサイト全体に基本認証を設定しています。そのサイトにAPIでリクエストしてくるところがあり、そこからのリクエストは基本認証をスキップして欲しいとの要望。ユーザ名とパスワードくらいいれればいいのに。
むかしのmod_auth_compatだと、Satisfy Anyとかでなんとかするんだけど、mod_authn_coreだとどうするんだろうと調べて試行錯誤。多分こうすればいいんだろうなぁというのが以下の通り。
<Location /> <RequireAny> AuthName "Hoge" AuthType Basic AuthUserFile .htpasswd Require user hoge fuga foo baa Require ip zz.zz.zz.zz #zz.zz.zz.zzからのリクエストは基本認証をスキップする。 <RequireAny> </Location>
で、Require user以外にもRequireがある場合は
以下では
となっているはずです。
<Location /> <RequireAll> AuthName "Hoge" AuthType Basic AuthUserFile .htpasswd Require user hoge fuga foo baa Require not ip xx.xx.xx.xx # xx.xx.xx.xxからのリクエストはdenyする <RequireAll> <RequireAny> Require ip aa.aa.aa.aa Require ip bb.bb.bb.bb </RequireAny> </Location>