{"id":388,"date":"2019-05-30T10:03:38","date_gmt":"2019-05-30T01:03:38","guid":{"rendered":"http:\/\/localhost:8000\/?p=388"},"modified":"2021-01-23T10:07:13","modified_gmt":"2021-01-23T01:07:13","slug":"docker-compose-nginx-https","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2019\/05\/docker-compose-nginx-https.html","title":{"rendered":"Docker Compose\u4e0a\u306eNginx\u3092HTTPS\u5bfe\u5fdc\u3059\u308b"},"content":{"rendered":"
\u30ed\u30fc\u30ab\u30eb\u958b\u767a\u7528\u306bDocker Comnpose\u3067\u52d5\u304b\u3057\u3066\u3044\u308bNginx\u3092HTTPS\u5bfe\u5fdc\u3059\u308b\u5fc5\u8981\u304c\u51fa\u3066\u304d\u305f\u306e\u3067\u3001\u81ea\u4f5c\u306eSSL\u8a3c\u660e\u66f8\u3092\u4f7f\u3063\u3066\u5bfe\u5fdc\u3059\u308b\u3053\u3068\u306b\u3057\u305f\u3002<\/p>\n
mkdir ssl\ncd ssl<\/code><\/pre>\n\u79d8\u5bc6\u9375\uff08KEY\uff09\u3092\u4f5c\u6210\u3059\u308b<\/h3>\n
\u6697\u53f7\u306b\u306fRSA 2048\u30d3\u30c3\u30c8\u3092\u4f7f\u7528\u3059\u308b\u3002<\/p>\n
openssl genrsa 2048 > server.key<\/code><\/pre>\n\u7f72\u540d\u30ea\u30af\u30a8\u30b9\u30c8\uff08CSR\uff09\u3092\u751f\u6210\u3059\u308b<\/h3>\n
SSL\u30b5\u30fc\u30d0\u8a3c\u660e\u66f8\u767a\u884c\u306b\u5fc5\u8981\u306a\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u3067\u3001\u8a8d\u8a3c\u5c40\u306f\u3053\u306e\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u5143\u306b\u5185\u5bb9\u3092\u7cbe\u67fb\u3057\u3066SSL\u8a3c\u660e\u66f8\u3092\u767a\u884c\u3059\u308b\u3089\u3057\u3044\u3002\uff08\u4eca\u56de\u306f\u81ea\u4f5c\u3059\u308b\u306e\u3067\u9069\u5f53\u3067OK\uff09<\/p>\n
openssl req -new -key server.key > server.csr\n> Country Name (2 letter code) []:81\n> State or Province Name (full name) []:tokyo\n> Locality Name (eg, city) []:tokyo\n> Organization Name (eg, company) []:none\n> Organizational Unit Name (eg, section) []:none\n> Common Name (eg, fully qualified host name) []:rinoguchi.com\n> Email Address []:hoge@gmail.com\n> A challenge password []:****<\/code><\/pre>\nSSL\u8a3c\u660e\u66f8\uff08CRT\uff09\u3092\u751f\u6210\u3059\u308b<\/h3>\n
x509\u306f\u516c\u958b\u9375\u57fa\u76e4\u306e\u898f\u683c\u306e\u540d\u524d\u3089\u3057\u3044\u3002100\u5e74\u306e\u8a2d\u5b9a\u3067SSL\u8a3c\u660e\u66f8\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n
openssl x509 -days 36500 -req -signkey server.key < server.csr > server.crt<\/code><\/pre>\nDocker\u306e\u8a2d\u5b9a<\/h2>\nDocker\u30b3\u30f3\u30c6\u30ca\u306e443\u30dd\u30fc\u30c8\u3092\u516c\u958b\u3059\u308b<\/h3>\n
\u30b3\u30f3\u30c6\u30ca\u5074\u306e80\uff08http\uff09\u3068443\uff08https\uff09\u30dd\u30fc\u30c8\u3092\u516c\u958b\u3057\u3001\u30db\u30b9\u30c8\u5074\u306e\u540c\u4e00\u30dd\u30fc\u30c8\u756a\u53f7\u3068\u7d10\u3065\u3051\u308b\u3002<\/p>\n
version: '3'\nservices:\n mynginx:\n build: .\n ports:\n - "80:80"\n - "443:443"<\/code><\/pre>\nSSL\u95a2\u4fc2\u306e\u30d5\u30a1\u30a4\u30eb\u3092Docker\u30a4\u30e1\u30fc\u30b8\u306b\u8ffd\u52a0\u3059\u308b<\/h3>\n
Dockerfile\u306b\u3066\u3001\u4f5c\u6210\u3057\u305fSSL\u95a2\u4fc2\u306e\u30d5\u30a1\u30a4\u30eb\u3092\/etc\/nginx\/ssl<\/code>\u306b\u8ffd\u52a0\u3059\u308b\u8a2d\u5b9a\u3092\u884c\u3046\u3002<\/p>\nFROM nginx:latest\nADD default.conf \/etc\/nginx\/conf.d\nADD ssl \/etc\/nginx\/ssl<\/code><\/pre>\nNginx\u306e\u8a2d\u5b9a<\/h2>\n
default.conf\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3092\u884c\u3046\u3002<\/p>\n
server {\n listen 80;\n server_name rinoguchi.com;\n return 301 https:\/\/$host$request_uri;\n}\n\nserver {\n listen 443 ssl;\n server_name rinoguchi.com;\n ssl_certificate \/etc\/nginx\/ssl\/server.crt; #SSL\u8a3c\u660e\u66f8\n ssl_certificate_key \/etc\/nginx\/ssl\/server.key; #\u79d8\u5bc6\u9375\n\n location \/ {\n proxy_pass http:\/\/host.docker.internal:8080\/;\n proxy_redirect default;\n }\n}<\/code><\/pre>\n\n- http\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306f\u3001https\u306b301\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\uff08Moved Permanently\uff09\u3059\u308b\u3002<\/li>\n
- SSL\u8a3c\u660e\u66f8\u3068\u79d8\u5bc6\u9375\u3092\u6307\u5b9a\u3059\u308b<\/li>\n<\/ul>\n
\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n
\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u8d77\u52d5\u3059\u308b\u3002<\/p>\n
docker-compose up --build<\/code><\/pre>\n\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u554f\u984c\u306a\u304f\u52d5\u4f5c\u3059\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u305f\u3002<\/p>\n
\nhttp:\/\/rinoguchi.com\/<\/code>\n\n- ->
https:\/\/rinoguchi.com\/<\/code>\u306b301 Moved Permanently<\/code>\u3055\u308c\u308b<\/li>\n<\/ul>\n<\/li>\nhttps:\/\/rinoguchi.com<\/code>\n\n- ->
200 response<\/code>\u304c\u8fd4\u5374\u3055\u308c\u308b<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u30ed\u30fc\u30ab\u30eb\u958b\u767a\u7528\u306bDocker Comnpose\u3067\u52d5\u304b\u3057\u3066\u3044\u308bNginx\u3092HTTPS\u5bfe\u5fdc\u3059\u308b\u5fc5\u8981\u304c\u51fa\u3066\u304d\u305f\u306e\u3067\u3001\u81ea\u4f5c\u306eSSL\u8a3c\u660e\u66f8\u3092\u4f7f\u3063\u3066\u5bfe\u5fdc\u3059\u308b\u3053\u3068\u306b\u3057\u305f\u3002 openssl\u3067\u79d8\u5bc6\u9375\u3001\u7f72\u540d\u30ea\u30af\u30a8\u30b9\u30c8\u3001SSL\u8a3c\u660e\u66f8\u3092\u4f5c\u6210 ssl\u3068\u3044\u3046\u30d5\u30a9\u30eb\u30c0\u3092\u4f5c\u6210\u3059\u308b mkdir ssl cd ssl \u79d8\u5bc6\u9375\uff08KEY\uff09\u3092\u4f5c\u6210\u3059\u308b \u6697\u53f7\u306b\u306fRSA 2048\u30d3\u30c3\u30c8\u3092\u4f7f\u7528\u3059\u308b\u3002 openssl genrsa 2048 > server.key \u7f72\u540d\u30ea\u30af\u30a8\u30b9\u30c8\uff08CSR\uff09\u3092\u751f\u6210\u3059\u308b SSL\u30b5\u30fc\u30d0\u8a3c\u660e\u66f8\u767a\u884c\u306b\u5fc5\u8981\u306a\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u3067\u3001\u8a8d\u8a3c\u5c40\u306f\u3053\u306e\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u5143\u306b\u5185\u5bb9\u3092\u7cbe\u67fb\u3057\u3066SSL\u8a3c\u660e\u66f8\u3092\u767a\u884c\u3059\u308b\u3089\u3057\u3044\u3002\uff08\u4eca\u56de\u306f\u81ea\u4f5c\u3059\u308b\u306e\u3067\u9069\u5f53\u3067OK\uff09 openssl req -new -key server.key > server.csr > Country Name (2 letter code) []:81 > S <\/span>Continue Reading<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[],"_links":{"self":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/388"}],"collection":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/comments?post=388"}],"version-history":[{"count":1,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/388\/revisions"}],"predecessor-version":[{"id":389,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/388\/revisions\/389"}],"wp:attachment":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/media?parent=388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/categories?post=388"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/tags?post=388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}