LoginSignup
0
0

More than 5 years have passed since last update.

Passenger(standalone)にて、ELBのHealthCheckはhttpで受けつつ残りはhttpsで通信させるようにする

Posted at

standaloneなpassengerの設定があまり見つからずに苦労したのでメモしておきます。

前提

  • elastic beanstalkで負荷分散な環境
  • the internet -> elb -> ec2(passenger standalone)なイメージ
  • httpで来た通信はhttpsへ301リダイレクトさせる
  • ただし、Elastic Load Balancerからはhttpにてhealthcheckが来るのでこれは受ける

設定

/etc/init.d/passenger
を見ると、--nginx-config-template している部分があるので、この読み込むファイルをebextensionsのfiles命令で書き換えてあげればよい。

nginx-config-template

要はX-Forwarded-Protoがhttpかつ、ELBからのhealthチェック以外は301すればよい。

ただし、nginxの設定ファイルでは、if文は使えるが、if A かつ B という構文は使えないので苦肉の策として、変数を置き、文字列結合して判定している。

set $redirect ''; # リダイレクト判定用文字列

if ($http_x_forwarded_proto != https) {
    set $redirect 1;
}

if ($http_user_agent !~* ELB-HealthChecker) {
    set $redirect "${$redirect}1";
}

if ($redirect = 11) {
    rewrite ^ https://$host$request_uri? permanent;
}

ヘルスチェックするパスが決まっている場合は、locationディレクティブで判定してあげても良いかもしれない。

0
0
0

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
0
0