CloudFront を使用時、https での通信でも、nginx の $scheme に http が入ってしまっている。
CloudFront-Forwarded-Proto ヘッダーに、original の scheme が入っているので、それを利用する。
CloudFront
Whitelist Headers に、CloudFront-Forwarded-Proto を追加。ホワイトリストというよりも、ヘッダーの追加。
Nginx
http_cloudfront_forwarded_proto が https であれば、 scheme を上書きして、次に流す。
location / { set $proto $scheme; if ($http_cloudfront_forwarded_proto = "https") { set $proto "https"; } proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $proto; proxy_set_header Host $http_host; proxy_pass http://app_sock; }