[Nginx-proxy 이미지 사용]

- docker-compose 를 통한 컨테이너 구축


- 서브도메인을 분기 시켜줄 프록시 컨테이너

* nginx-proxy.yaml


version: '2'
services:
nginx-proxy:
container_name: nginx-proxy
image: jwilder/nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /home/test/nginx-proxy/log:/var/log/nginx

networks:
default:
external:
name: nginx-proxy



- 기본 웹서버 컨테이너

* nginx-www.yaml


version: '2'
services:
nginx-www:
image: nginx:latest
environment:
- VIRTUAL_HOST=www.domain.com
container_name: nginx-www

networks:
default:
external:
name: nginx-proxy



- 서브도메인을 테스트 할 test 컨테이너 (test 대신 다른 웹서버 이미지를 사용해서 테스트 해야합니다.)

* test.yaml


version: '2'
services:
test-container:
image: test
container_name: test
environment:
- VIRTUAL_HOST=sub.domain.com
- VIRTUAL_PORT=3000

networks:
default:
external:
name: nginx-proxy



- 프록시 컨테이너 내 nginx 설정 파일 확인

/etc/nginx/conf.d/default.conf

~~~
server {
    server_name _; # This is just an invalid value which will never trigger on a real hostname.
    listen 80;
    access_log /var/log/nginx/access.log vhost;
    return 503;
version: '2'
}
# www.domain.com
upstream www.domain.com {
                ## Can be connected with "nginx-proxy" network
            # nginx-www
            server 192.0.0.1:80;
}
server {
    server_name www.domain.com;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    location / {
        proxy_pass http://www.domain.com;
    }
}
# test.domain.com
upstream test.domain.com {
            ## Can be connected with "nginx-proxy" network
            # test web server container
            server 192.0.0.2:3000;
}
server {
    server_name test.domain.com;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    location / {
        proxy_pass http://test.domain.com;
    }
}



---------------

+ Recent posts