{"id":398,"date":"2019-05-24T10:29:35","date_gmt":"2019-05-24T01:29:35","guid":{"rendered":"http:\/\/localhost:8000\/?p=398"},"modified":"2021-01-23T10:31:13","modified_gmt":"2021-01-23T01:31:13","slug":"same-domain-in-nginx","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2019\/05\/same-domain-in-nginx.html","title":{"rendered":"\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3067\u958b\u767a\u4e2d\u306e\u8907\u6570\u30a2\u30d7\u30ea\u30b5\u30fc\u30d0\u306e\u30c9\u30e1\u30a4\u30f3\u3092Nginx\u3067\u7d71\u4e00\u3059\u308b"},"content":{"rendered":"
\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3067\u958b\u767a\u4e2d\u306e\u8907\u6570\u30a2\u30d7\u30ea\u30b5\u30fc\u30d0\u306e\u30c9\u30e1\u30a4\u30f3\u3092\u7d71\u4e00\u3059\u308b\u5fc5\u8981\u304c\u51fa\u3066\u304d\u305f\u306e\u3067\u3001Docker Compose\u3092\u4f7f\u3063\u3066Nginx\u3067\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3092\u7acb\u3066\u308b\u3053\u3068\u306b\u3057\u305f\u3002<\/p>\n
http:\/\/rinoguchi.io\/hoge<\/code> --proxy--> http:\/\/localhost:8080<\/code><\/li>\nhttp:\/\/rinoguchi.io\/fuga<\/code> --proxy--> http:\/\/localhost:8081<\/code><\/li>\n<\/ul>\n\u30e2\u30c1\u30d9\u30fc\u30b7\u30e7\u30f3<\/h2>\n
Docker\u3067\u7acb\u3061\u4e0a\u3052\u305f\u8907\u6570\u30a2\u30d7\u30ea\u30b5\u30fc\u30d0\u3092\u3001Docker Compose\u3092\u4f7f\u3063\u3066Nginx\u3067\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3059\u308b\u8a71\u306f\u7d50\u69cb\u3042\u308b\u306e\u3060\u304c\u3001Docker\u3092\u4f7f\u308f\u305a\u7acb\u3061\u4e0a\u3052\u305f\u30a2\u30d7\u30ea\u30b5\u30fc\u30d0\u306e\u8a71\u306f\u767a\u898b\u3067\u304d\u306a\u304b\u3063\u305f\u3002<\/p>\n
\u500b\u4eba\u7684\u306b\u306f\u3001\u958b\u767a\u5bfe\u8c61\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306fAutoReload\u304c\u52b9\u304b\u306a\u304f\u306a\u308b\u306e\u3067Docker\u3067\u306f\u7acb\u3061\u4e0a\u3052\u306a\u3044\u65b9\u304c\u826f\u3044\u3068\u8003\u3048\u3066\u3044\u308b\u3002\u306a\u306e\u3067\u3001\u4eca\u56deDocker\u3092\u4f7f\u308f\u305a\u306b\u7acb\u3061\u4e0a\u3052\u305f\u30a2\u30d7\u30ea\u30b5\u30fc\u30d0\u3092\u3001Nginx\u3067\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3059\u308b\u624b\u9806\u3092\u8a18\u8f09\u3057\u305f\u3044\u3068\u601d\u3046\u3002<\/p>\n
\u60f3\u5b9a\u3059\u308bRequest\u306e\u6d41\u308c<\/h2>\n\n- browser\u304c\u30ea\u30af\u30a8\u30b9\u30c8:
http:\/\/rinoguchi.io\/hoge<\/code><\/li>\n- hosts\u304c\u540d\u524d\u89e3\u6c7a:
rinoguchi.io<\/code> -> 127.0.0.1<\/code><\/li>\n- docker\u304c\u30dd\u30fc\u30c8\u30d0\u30a4\u30f3\u30c9:
127.0.0.1:80<\/code> -> Nginx\u306eDocker\u30b3\u30f3\u30c6\u30ca:80<\/code><\/li>\n- nginx\u304c\u30d7\u30ed\u30ad\u30b7:
rinoguchi.io\/hoge<\/code> -> localhost:8080<\/code><\/li>\n- application\u304c\u5fdc\u7b54:
localhost:8080<\/code><\/li>\n<\/ol>\n\u8a2d\u5b9a<\/h2>\nHosts\u306e\u8a2d\u5b9a<\/h3>\n
\/etc\/hosts<\/code>\u306b\u3066rinoguchi.io<\/code>\u3068\u3044\u3046host\u540d\u306b\u5bfe\u3057\u3066\u3001127.0.0.1<\/code>\u3092\u5272\u308a\u5f53\u3066\u308b<\/p>\nsudo vi \/etc\/hosts\n\n+ 127.0.0.1 rinoguchi.io<\/code><\/pre>\nNginx\u306e\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u8a2d\u5b9a<\/h3>\n
default.conf<\/code>\u3092\u4f5c\u6210\u3059\u308b\u3002\u3053\u308c\u306f\u672c\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u7528\u306eDocker\u30a4\u30e1\u30fc\u30b8\u306b\u30b3\u30d4\u30fc\u3055\u308c\u308b\u3002<\/p>\nserver {\n listen 80;\n server_name rinoguchi.io;\n\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header Host $host;\n proxy_set_header X-Forwarded-Proto $scheme;\n proxy_set_header X-Forwarded-Host $host;\n proxy_set_header X-Forwarded-Server $host;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\n location \/hoge\/ {\n proxy_pass http:\/\/host.docker.internal:8080\/;\n }\n\n location \/fuga\/ {\n proxy_pass http:\/\/host.docker.internal:8081\/;\n }\n\n access_log \/dev\/stdout;\n error_log \/dev\/stderr debug;\n}<\/code><\/pre>\n\nhost.docker.internal<\/code>\u306fDocker\u30b3\u30f3\u30c6\u30ca\u5185\u3067\u4f7f\u3048\u308b\u30db\u30b9\u30c8\u30de\u30b7\u30f3\u306e\u30db\u30b9\u30c8\u540d\n\n- https:\/\/docs.docker.com\/docker-for-mac\/networking\/#i-want-to-connect-from-a-container-to-a-service-on-the-host<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n
Dockerfile\u306e\u4f5c\u6210<\/h3>\n
\u516c\u5f0f\u306eNginx\u306eDocker\u30a4\u30e1\u30fc\u30b8\u3092\u5143\u306b\u3001\u672c\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u7528\u306eNginx\u306eDocker\u30a4\u30e1\u30fc\u30b8\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n
FROM nginx:latest\nADD default.conf \/etc\/nginx\/conf.d<\/code><\/pre>\nDocker Compose\u306e\u8a2d\u5b9a<\/h3>\n
docker-compose.yml<\/code>\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\nversion: '3'\nservices:\n mynginx:\n build: .\n ports:\n - "80:80"<\/code><\/pre>\n\n- \u5148\u307b\u3069\u4f5c\u6210\u3057\u305f
default.conf<\/code>\u3092\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u8ffd\u52a0<\/li>\n- \u30db\u30b9\u30c8\u30de\u30b7\u30f3\u306e80\u756a\u30dd\u30fc\u30c8\u3092\u30b3\u30f3\u30c6\u30ca\u306e80\u756a\u30dd\u30fc\u30c8\u306b\u30d0\u30a4\u30f3\u30c9<\/li>\n<\/ul>\n
\u5b9f\u884c<\/h2>\n
\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3057\u3001Docker\u30a4\u30e1\u30fc\u30b8\u3092\u4f5c\u6210\u3057\u3066\u3001Docker\u30b3\u30f3\u30c6\u30ca\u3092\u7acb\u3061\u4e0a\u3052\u308b\u3002
\n--build<\/code>\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u6bce\u56deDocker\u30a4\u30e1\u30fc\u30b8\u3092\u518d\u4f5c\u6210\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3042\u308b\u3002<\/p>\ndocker-compose up --build<\/code><\/pre>\n\u3053\u308c\u306b\u3088\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30d7\u30ed\u30ad\u30b7\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u3001\u30c9\u30e1\u30a4\u30f3\u3092rinoguchi.io<\/code>\u306b\u7d71\u5408\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u305f\u3002<\/p>\n\nhttp:\/\/rinoguchi.io\/hoge<\/code> => proxy => http:\/\/localhost:8080<\/code> <\/li>\nhttp:\/\/rinoguchi.io\/fuga<\/code> => proxy => http:\/\/localhost:8081<\/code> <\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3067\u958b\u767a\u4e2d\u306e\u8907\u6570\u30a2\u30d7\u30ea\u30b5\u30fc\u30d0\u306e\u30c9\u30e1\u30a4\u30f3\u3092\u7d71\u4e00\u3059\u308b\u5fc5\u8981\u304c\u51fa\u3066\u304d\u305f\u306e\u3067\u3001Docker Compose\u3092\u4f7f\u3063\u3066Nginx\u3067\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3092\u7acb\u3066\u308b\u3053\u3068\u306b\u3057\u305f\u3002 \u5b9f\u73fe\u3057\u305f\u3044\u3053\u3068 http:\/\/rinoguchi.io\/hoge –proxy–> http:\/\/localhost:8080 http:\/\/rinoguchi.io\/fuga –proxy–> http:\/\/localhost:8081 \u30e2\u30c1\u30d9\u30fc\u30b7\u30e7\u30f3 Docker\u3067\u7acb\u3061\u4e0a\u3052\u305f\u8907\u6570\u30a2\u30d7\u30ea\u30b5\u30fc\u30d0\u3092\u3001Docker Compose\u3092\u4f7f\u3063\u3066Nginx\u3067\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3059\u308b\u8a71\u306f\u7d50\u69cb\u3042\u308b\u306e\u3060\u304c\u3001Docker\u3092\u4f7f\u308f\u305a\u7acb\u3061\u4e0a\u3052\u305f\u30a2\u30d7\u30ea\u30b5\u30fc\u30d0\u306e\u8a71\u306f\u767a\u898b\u3067\u304d\u306a\u304b\u3063\u305f\u3002 \u500b\u4eba\u7684\u306b\u306f\u3001\u958b\u767a\u5bfe\u8c61\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306fAutoReload\u304c\u52b9\u304b\u306a\u304f\u306a\u308b\u306e\u3067Docker\u3067\u306f\u7acb\u3061\u4e0a\u3052\u306a\u3044\u65b9\u304c\u826f\u3044\u3068\u8003\u3048\u3066\u3044\u308b\u3002\u306a\u306e\u3067\u3001\u4eca\u56deDocker\u3092\u4f7f\u308f\u305a <\/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":[34],"tags":[],"_links":{"self":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/398"}],"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=398"}],"version-history":[{"count":1,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/398\/revisions"}],"predecessor-version":[{"id":400,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/398\/revisions\/400"}],"wp:attachment":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/media?parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/categories?post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/tags?post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}