LoginSignup
47
46

More than 5 years have passed since last update.

nginxで特定のIPからは公開したいけどそれ以外はBASIC認証にしたいときの設定

Last updated at Posted at 2016-04-27

本件、件名の件名の対応をやろうとググったら
昔自分が書いた(2013/02/21)会社のブログが出てて(記憶力のなさにビビった)
だけど該当ページがなくなっててw
キャッシュからからQiitaに再掲

やりたいことを端的にいうと
外部にあるテストサーバーとかで
社内からはアクセスは無条件で公開したいけど
それ以外のアクセスはBASIC認証にしたい場合の設定です
(社内だけじゃなく、外部からもチェックしなきゃいけない場合とか)

いきなり設定どーん

location / {
    satisfy any;
    allow 123.123.123.123;
    deny all;

    auth_basic  "basic authentication";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

きもはsatisfy any;
これが無いと 指定IP and Basic認証で許可になるけど
指定していると 指定IP or Basic認証になりんす
複数IPの場合は

location / {
    satisfy any;
    allow 123.123.123.123;
    allow 111.111.111.111;
    deny all;

    auth_basic  "basic authentication";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

でOKよ

.htpasswdの設定とかは割愛

ではまた

47
46
1

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
47
46