ELBでSSLの設定をしている場合には、ぶら下がってるサーバーへは80番で常に来ます。なのでこれだとSSLでアクセスされているかどうかわかりません。
ですが、httpsかどうかは$http_x_forwarded_proto
という変数に入ってるので、それで判断しましょうという話です。
例では、TOPにhttpsで来た時だけhttpにrewriteし、それ以外のページにhttpで来た時にはhttpsにrewriteするという処理を書いてます。
/etc/nginx/conf.d/sample.conf
location = / {
+ if ($http_x_forwarded_proto = "https") {
+ rewrite ^(.*) http://$server_name$1
+ break;
+ }
...
}
location / {
+ if ($http_x_forwarded_proto != "https") {
+ rewrite ^(.*) https://$server_name$1
+ break;
+ }