Skip to content

Instantly share code, notes, and snippets.

@gorou-178
Created June 30, 2014 05:01
Show Gist options
  • Save gorou-178/694ad9abf7fc01d7bf51 to your computer and use it in GitHub Desktop.
Save gorou-178/694ad9abf7fc01d7bf51 to your computer and use it in GitHub Desktop.
ELB配下のEC2のnginxで、httpをhttpsにリダイレクトする方法。 http://live-cast.asia/blog/2014/06/redirect-https-to-http-in-the-instance-of-the-elb-under-nginx.html
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
set $redirect "";
if ($http_x_forwarded_proto != 'https') {
set $redirect "1";
}
if ($http_user_agent !~* ELB-HealthChecker) {
set $redirect "${redirect}1";
}
if ($http_host ~ "www.example.com") {
set $redirect "${redirect}1";
}
if ($redirect = "111") {
rewrite ^ https://$host$request_uri? permanent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment