Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Last active March 3, 2017 10:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkuchiki/348a549e2171aaf39988172154c4a35e to your computer and use it in GitHub Desktop.
Save tkuchiki/348a549e2171aaf39988172154c4a35e to your computer and use it in GitHub Desktop.
Nginx は if の中で使えないディレクティブがあるので、error_page と組み合わせてみる

特定の IP からのアクセスのときだけ認証を通さないで proxy したい

  • Nginx は if の中で使えないディレクティブがある
    • error_page と組み合わせる
      • error_page で実行する location 内で include したり、認証設定を書く

以下の設定は error

if ($geo = 0) {
    include /path/to/conf;
}
geo $geo {
default 0;
127.0.0.1/32 1;
}
location / {
error_page 418 = @auth_required;
recursive_error_pages on;
if ($geo = 0) {
return 418;
}
proxy_pass http://127.0.0.1;
}
location @auth_required {
include /path/to/conf;
proxy_pass http://127.0.0.1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment