2017-09-30 154 views
1

ELB healthcheckの基本認証を実装しようとしています。 私はELBは私がするようにnginx.confを変更しようとしたため、基本認証にAWB ELBの基本認証を避ける方法nginx設定での健康チェック

unhealthy in target-group hogehoge due to (reason Health checks failed with these codes: [401])

を返し、以下に示す401エラーを回避するために、nginxのファイル構成を把握するためにかなり検索しましたそれを避けてください、しかしそれは動作しません。 以下のコードは私に[emerg] "server" directive is not allowed hereエラーを与えます。

http { 
    server { 
     location/{ 
      if (!$http_x_forwarded_for) { 
       auth_basic   'Please enter ID and password'; 
       auth_basic_user_file /usr/src/redmine/.htpasswd; 
      } 
     } 
    } 
} 

基本認証のためにELB healthcheckで401エラーを回避するにはどうすればよいですか?

ありがとうございました。

+0

あなたは基本認証を有効にするためのカスタム設定でそれを追加しておく必要がありますか?どのようにして最初に認証を有効にしましたか? –

答えて

3

最も簡単な方法は、例えば、ELBの場所を作成するには、次のようになります。

location /elb-status { 
    access_log off; 
    return 200; 
} 

は、あなただけがあなたに何かを見たい場合は/elb-status

するPing Pathを変更する必要がありますデフォルトのapplication/octet-streamに変更する必要があります。ブラウザでファイルを保存するように指定すると、次のようになります。

location /elb-status { 
    access_log off; 
    return 200 'your text goes here'; 
    add_header Content-Type text/plain; 
} 

あなたはユーザーエージェントに対してチェックしたい場合、このようなものを使用することができる:

set $block 1; 

# Allow all the ELB health check agents. 
if ($http_user_agent ~* '^ELB-HealthChecker\/.*$') { 
    set $block 0; 
} 
if (!$http_x_forwarded_for) { 
    set $block 1 
} 

if ($block = 1) { 
    auth_basic   'Please enter ID and password'; 
    auth_basic_user_file /usr/src/redmine/.htpasswd; 
} 
+0

私はip-addressに基づいて基本認証を有効/無効にしたいので、私はあなたの2番目のオプションを使いました。 ありがとうございました! –

+0

''もし ''がnginx(私はあなたが見るでしょう)で邪悪であることに注意してください、 '$ block'を設定する代わりにmapディレクティブを使うべきです –

関連する問題