トップページ("/")はHTTPで見せるけど, それ以外のページ(= ログイン後)はHTTPSのみ許容するという設定. server directive内で使う.
nginxは多段ifが使えないので力技な書き方になる(他にいいやり方あるのだろうか...)
set $https_and_top "";
if ( $scheme = "https" ) { set $https_and_top "${https_and_top}HTTPS"; }
if ( $request_uri = "/" ) { set $https_and_top "${https_and_top}&TOP"; }
if ( $https_and_top = "HTTPS&TOP" ) {
return 301 http://hoge.com/;
}
set $http_and_not_top "";
if ( $scheme = "http" ) { set $http_and_not_top "${http_and_not_top}HTTP"; }
if ( $request_uri != "/" ) { set $http_and_not_top "${http_and_not_top}&NOTTOP"; }
if ( $http_and_not_top = "HTTP&NOTTOP") {
return 301 https://hoge.com$request_uri;
}