카타코더 Docker - Load Balancing Containers 편집하기

경고: 로그인하지 않았습니다. 편집을 하면 IP 주소가 공개되게 됩니다. 로그인하거나 계정을 생성하면 편집자가 사용자 이름으로 기록되고, 다른 장점도 있습니다.

편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.

최신판 당신의 편집
1번째 줄: 1번째 줄:
==개요==
==개요==
;카타코더 Docker - Load Balancing Containers
{{카타코더|Docker|2}}
{{카타코더|Docker|2}}


==NGINX Proxy==
====
<source lang='console'>
<source lang='console'>
$ docker run -d -p 80:80 -e DEFAULT_HOST=proxy.example -v /var/run/docker.sock:/tmp/docker.sock:ro --name nginx jwilder/nginx-proxy
c884bfe63c8abe1b7fddfe1a7ffd2a97770830d3a40cef809a70a2ac8db2b0a7
</source>
<source lang='console'>
$ curl http://docker
<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body bgcolor="white">
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>nginx/1.14.1</center>
</body>
</html>
</source>
==Single Host==
<source lang='console'>
$ docker run -d -p 80 -e VIRTUAL_HOST=proxy.example katacoda/docker-http-server
2fc6828eb8f34fa30d070cd49dbd5e7a44077abc717f5b56f17d29e3ae082b6e
</source>
<source lang='console'>
$ curl http://docker
<h1>This request was processed by host: 2fc6828eb8f3</h1>
</source>
==Cluster==
<source lang='console'>
$ docker run -d -p 80 -e VIRTUAL_HOST=proxy.example katacoda/docker-http-server
a3a91d74125721f142ae755431ae4a935f9512ac00b69589b3d11b07e3b34eb2
</source>
<source lang='console'>
$ curl http://docker
<h1>This request was processed by host: a3a91d741257</h1>
</source>
==Generated NGINX Configuration==
<source lang='console'>
$ docker exec nginx cat /etc/nginx/conf.d/default.conf
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
  default $http_x_forwarded_proto;
  ''      $scheme;
}
# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
# server port the client connected to
map $http_x_forwarded_port $proxy_x_forwarded_port {
  default $http_x_forwarded_port;
  ''      $server_port;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, deleteany
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
  default upgrade;
  '' close;
}
# Apply fix for very long server names
server_names_hash_bucket_size 128;
# Default dhparam
ssl_dhparam /etc/nginx/dhparam/dhparam.pem;
# Set appropriate X-Forwarded-Ssl header
map $scheme $proxy_x_forwarded_ssl {
  default off;
  https on;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
                '"$request" $status $body_bytes_sent '
                '"$http_referer" "$http_user_agent"';
access_log off;
resolver 8.8.8.8;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
# Mitigate httpoxy attack (see README for details)
proxy_set_header Proxy "";
server {
        server_name _; # This is just an invalid value which will nevertrigger on a real hostname.
        listen 80;
        access_log /var/log/nginx/access.log vhost;
        return 503;
}
# proxy.example
upstream proxy.example {
                                ## Can be connected with "bridge" network
                        # hopeful_kare
                        server 172.18.0.4:80;
                                ## Can be connected with "bridge" network
                        # silly_borg
                        server 172.18.0.3:80;
}
server {
        server_name proxy.example;
        listen 80 default_server;
        access_log /var/log/nginx/access.log vhost;
        location / {
                proxy_pass http://proxy.example;
        }
}
</source>
<source lang='console'>
$ docker logs nginx
WARNING: /etc/nginx/dhparam/dhparam.pem was not found. A pre-generated dhparam.pem will be used for now while a new one
is being generated in the background.  Once the new dhparam.pem is in place, nginx will be reloaded.
forego    | starting dockergen.1 on port 5000
forego    | starting nginx.1 on port 5100
dockergen.1 | 2019/03/23 11:15:53 Generated '/etc/nginx/conf.d/default.conf' from 1 containers
dockergen.1 | 2019/03/23 11:15:53 Watching docker events
dockergen.1 | 2019/03/23 11:15:53 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
nginx.1    | docker 172.17.0.60 - - [23/Mar/2019:11:16:01 +0000] "GET /HTTP/1.1" 503 213 "-" "curl/7.47.0"
dockergen.1 | 2019/03/23 11:16:19 Received event start for container 2fc6828eb8f3
dockergen.1 | 2019/03/23 11:16:19 Generated '/etc/nginx/conf.d/default.conf' from 2 containers
dockergen.1 | 2019/03/23 11:16:19 Running 'nginx -s reload'
nginx.1    | docker 172.17.0.60 - - [23/Mar/2019:11:16:28 +0000] "GET /HTTP/1.1" 200 58 "-" "curl/7.47.0"
dockergen.1 | 2019/03/23 11:16:47 Received event start for container a3a91d741257
dockergen.1 | 2019/03/23 11:16:47 Generated '/etc/nginx/conf.d/default.conf' from 3 containers
dockergen.1 | 2019/03/23 11:16:47 Running 'nginx -s reload'
2019/03/23 11:16:52 [notice] 47#47: signal process started
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
dhparam generation complete, reloading nginx
nginx.1    | docker 172.17.0.60 - - [23/Mar/2019:11:16:55 +0000] "GET /HTTP/1.1" 200 58 "-" "curl/7.47.0"
</source>
</source>

제타위키에서의 모든 기여는 크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 라이선스로 배포된다는 점을 유의해 주세요(자세한 내용에 대해서는 제타위키:저작권 문서를 읽어주세요). 만약 여기에 동의하지 않는다면 문서를 저장하지 말아 주세요.
또한, 직접 작성했거나 퍼블릭 도메인과 같은 자유 문서에서 가져왔다는 것을 보증해야 합니다. 저작권이 있는 내용을 허가 없이 저장하지 마세요!

취소 편집 도움말 (새 창에서 열림)