{"id":1054,"date":"2017-08-13T10:20:21","date_gmt":"2017-08-13T01:20:21","guid":{"rendered":"http:\/\/blue-bear.jp\/kb\/?p=1054"},"modified":"2017-08-13T10:20:21","modified_gmt":"2017-08-13T01:20:21","slug":"aws-elb-nginxapacheiis-%e3%81%a7-http%e3%82%92https%e3%81%ab%e3%83%aa%e3%83%80%e3%82%a4%e3%83%ac%e3%82%af%e3%83%88","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/aws-elb-nginxapacheiis-%e3%81%a7-http%e3%82%92https%e3%81%ab%e3%83%aa%e3%83%80%e3%82%a4%e3%83%ac%e3%82%af%e3%83%88\/","title":{"rendered":"AWS ELB + Nginx\/Apache\/IIS \u3067 http\u3092HTTPS\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8"},"content":{"rendered":"<p>AWS Cloudfront\u3067HTTP\u3092HTTPS\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3057\u3066\u3044\u305f\u304c\u3001\u4e00\u90e8\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u304c\u8868\u793a\u3055\u308c\u306a\u304b\u3063\u305f\u308a\u3068\u3001\u5f71\u97ff\u304c\u5927\u304d\u304b\u3063\u305f\u3002<\/p>\n<p>\u305f\u3060SSL\u5316\u306f\u3057\u305f\u304b\u3063\u305f\u306e\u3067\u3001AWS ELB\u3067SSL\u5316\u3092\u884c\u3046\u3053\u3068\u306b\u3057\u305f\u3002<\/p>\n<p>CloudFront\u3067\u306fHTTPS\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u306e\u306f\u8d85\u7c21\u5358\u3060\u3063\u305f\u306e\u3060\u304c\u3001ELB\u306b\u306f\u305d\u306e\u6a5f\u80fd\u304c\u306a\u3044\u3002<\/p>\n<p>\u305d\u306e\u4ee3\u308f\u308aELB\u306b\u306fX-FORWARDED-PROTO\u304c\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001X-FORWARDED-PROTO\u306bHTTPS\u304c\u306a\u3051\u308c\u3070\u3001301\u3067HTTPS\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3055\u305b\u308b<\/p>\n<h2>Nginx<\/h2>\n<pre>server {\r\n    listen 80;\r\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000#....\r\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\r\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000#\u3053\u3053\u3092\u8ffd\u52a0\r\n    if ($http_x_forwarded_proto != https) {\r\n      return 301 https:\/\/$host$request_uri;\r\n    }\r\n}\r\n<\/pre>\n<p>\u3082\u3057\u304f\u306f<\/p>\n<pre>server {\r\n    listen 80;\r\n    #....\r\n\r\n    location \/ {\r\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000    #\u3053\u3053\u3092\u8ffd\u52a0\r\n        if ($http_x_forwarded_proto != 'https') {\r\n            return 301 https:\/\/$server_name$request_uri;\r\n        }\r\n\r\n    #....\r\n    }\r\n}\r\n<\/pre>\n<h2>Apache<\/h2>\n<pre class=\"\">&lt;VirtualHost *:80&gt;\r\n #...\r\n RewriteEngine On\r\n RewriteCond %{HTTP:X-Forwarded-Proto} !https\r\n RewriteRule ^(.*)$ https:\/\/%{SERVER_NAME}%{REQUEST_URI} [NE]\r\n #...\r\n&lt;\/VirtualHost&gt;\r\n<\/pre>\n<h2>IIS<\/h2>\n<pre class=\"\">&lt;rewrite xdt:Transform=\"Insert\"&gt;\r\n &lt;rules&gt;\r\n &lt;rule name=\"HTTPS rewrite behind ELB rule\" stopProcessing=\"true\"&gt;\r\n &lt;match url=\"^(.*)$\" ignoreCase=\"false\" \/&gt;\r\n &lt;conditions&gt;\r\n &lt;add input=\"{HTTP_X_FORWARDED_PROTO}\" pattern=\"^http$\" ignoreCase=\"false\" \/&gt;\r\n &lt;\/conditions&gt;\r\n &lt;action type=\"Redirect\" redirectType=\"Found\" url=\"https:\/\/{SERVER_NAME}{URL}\" \/&gt;\r\n &lt;\/rule&gt;\r\n &lt;\/rules&gt;\r\n&lt;\/rewrite&gt;\r\n<\/pre>\n<h2>\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u7528\u8a2d\u5b9a<\/h2>\n<p>ELB\u306e\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u304c80\u756a\u306e\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u7528\u30da\u30fc\u30b8\u3060\u3051\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b<\/p>\n<pre>\r\nserver {\r\n    listen 80 default_server;\r\n    server_name \"\";\r\n    location \/health {\r\n        access_log off;\r\n        return  200;\r\n    }\r\n}\r\nserver {\r\n    listen 80;\r\n    server_name app.yourdomain.com;\r\n    #....\r\n    location \/ {\r\n        if ($http_x_forwarded_proto != 'https') {\r\n            return 301 https:\/\/$server_name$request_uri;\r\n        }\r\n        try_files $uri $uri\/ \/index.php?$args;\r\n    }\r\n    #....\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>AWS Cloudfront\u3067HTTP\u3092<\/p>\n","protected":false},"author":1,"featured_media":45,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1054"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=1054"}],"version-history":[{"count":1,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1054\/revisions"}],"predecessor-version":[{"id":1055,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1054\/revisions\/1055"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media\/45"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=1054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=1054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=1054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}