paranitips

Never stop learning! がモットーのゆるふわエンジニアブログ

nginxでリバースプロキシするときにBasic認証を解除する

例えば、画像へのリクエストをnginxでS3にリバースプロキシしていると、テスト用のBasic認証で閉じられた環境で適用するとS3側で弾かれてしまいます。

サイト全体にBasic認証かけてる。

http {
  ...
  auth_basic "Restricted";
  auth_basic_user_file "/path/to/passwd";
  ...

以下のように画像へのリクエストでAuthorizationヘッダを空文字で上書きすればOKです。

location /images/ {
  proxy_set_header Authorization "";
  proxy_pass "http://hogehoge.com"
}

ちなみにauth_basic offは効果ありませんでした。

location /images/ {
  auth_basic off;  # 効果なし
  proxy_pass "http://hogehoge.com"
}

参考