commit 42e06bf556d5c1b2c850019e3bf1ea6b0e4ca878 Author: Alex Hyett Date: Fri Mar 18 14:10:59 2022 +0000 Add files for youtube demo diff --git a/README.md b/README.md new file mode 100644 index 0000000..a98b667 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# traefik-vs-nginx-docker-youtube + +Examples showing how to use Traefik and Nginx for Reverse Proxy. + +This repository is to complement my YouTube video on this topic, [Traefik vs nginx: Docker Reverse Proxy](https://www.youtube.com/channel/UCm6lURZOeBVCZ5hJpqlUB-g) + +## nginx + +``` +docker-compose -f docker-compose.nginx.yml up +``` + +## nginx proxy + +``` +docker-compose -f docker-compose.nginx-proxy.yml up +``` + +## traefik + +``` +docker-compose -f docker-compose.traefik.yml up +``` + +## traefik with docker network + +``` +docker-compose -f docker-compose.traefik-network.yml up & +docker-compose -f docker-compose.services.yml up +``` \ No newline at end of file diff --git a/default.conf b/default.conf new file mode 100644 index 0000000..0926a4d --- /dev/null +++ b/default.conf @@ -0,0 +1,54 @@ +# HTTP Server +server { + listen 80 default_server; + root /srv/www; + + server_name localhost; + + error_log stderr notice; + + location /whoami { + proxy_pass http://whoami; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Real-IP $remote_addr; + + proxy_http_version 1.1; + proxy_set_header Connection "upgrade"; + proxy_set_header Upgrade $http_upgrade; + proxy_read_timeout 600s; + + access_log off; + } + + location /ghost { + proxy_pass http://ghost:2368; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Real-IP $remote_addr; + + proxy_http_version 1.1; + proxy_set_header Connection "upgrade"; + proxy_set_header Upgrade $http_upgrade; + proxy_read_timeout 600s; + + access_log off; + } + + location /ghost2 { + proxy_pass http://ghost2:2368; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Real-IP $remote_addr; + + proxy_http_version 1.1; + proxy_set_header Connection "upgrade"; + proxy_set_header Upgrade $http_upgrade; + proxy_read_timeout 600s; + + access_log off; + } +} \ No newline at end of file diff --git a/docker-compose.nginx-proxy.yml b/docker-compose.nginx-proxy.yml new file mode 100644 index 0000000..1540149 --- /dev/null +++ b/docker-compose.nginx-proxy.yml @@ -0,0 +1,32 @@ +version: '3.4' +services: + nginx: + image: nginxproxy/nginx-proxy + ports: + - '80:80' + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + + whoami: + image: 'containous/whoami:latest' + environment: + VIRTUAL_HOST: localhost + VIRTUAL_PATH: /whoami + VIRTUAL_PORT: 80 + + ghost: + image: 'ghost:latest' + environment: + url: http://localhost/ghost + VIRTUAL_HOST: localhost + VIRTUAL_PATH: /ghost + VIRTUAL_PORT: 2368 + + ghost2: + image: 'ghost:latest' + environment: + url: http://localhost/ghost2 + VIRTUAL_HOST: localhost + VIRTUAL_PATH: /ghost2 + VIRTUAL_PORT: 2368 + diff --git a/docker-compose.nginx.yml b/docker-compose.nginx.yml new file mode 100644 index 0000000..339388e --- /dev/null +++ b/docker-compose.nginx.yml @@ -0,0 +1,22 @@ +version: '3.4' +services: + nginx: + image: nginx:latest + ports: + - '80:80' + volumes: + - "./default.conf:/etc/nginx/conf.d/default.conf" + + whoami: + image: 'containous/whoami:latest' + + ghost: + image: 'ghost:latest' + environment: + url: http://localhost/ghost + + ghost2: + image: 'ghost:latest' + environment: + url: http://localhost/ghost2 + diff --git a/docker-compose.services.yml b/docker-compose.services.yml new file mode 100644 index 0000000..9379c60 --- /dev/null +++ b/docker-compose.services.yml @@ -0,0 +1,25 @@ +version: '3.4' +services: + whoami2: + image: 'traefik/whoami' + labels: + - 'traefik.enable=true' + - 'traefik.http.routers.whoami2.rule=PathPrefix(`/whoami2{regex:$$|/.*}`)' + - 'traefik.http.services.whoami2.loadbalancer.server.port=80' + networks: + - home + + ghost2: + image: 'ghost:latest' + environment: + url: http://localhost/ghost2 + labels: + - 'traefik.enable=true' + - 'traefik.http.routers.ghost2.rule=PathPrefix(`/ghost2{regex:$$|/.*}`)' + - 'traefik.http.services.ghost2.loadbalancer.server.port=2368' + networks: + - home + +networks: + home: + external: true \ No newline at end of file diff --git a/docker-compose.traefik-network.yml b/docker-compose.traefik-network.yml new file mode 100644 index 0000000..879de1e --- /dev/null +++ b/docker-compose.traefik-network.yml @@ -0,0 +1,36 @@ +version: '3.4' +services: + traefik: + image: 'traefik:latest' + ports: + - '80:80' + - '8080:8080' + volumes: + - './traefik.yml:/etc/traefik/traefik.yml' + - '/var/run/docker.sock:/var/run/docker.sock:ro' + networks: + - home + + whoami: + image: 'traefik/whoami' + labels: + - 'traefik.enable=true' + - 'traefik.http.routers.whoami.rule=PathPrefix(`/whoami{regex:$$|/.*}`)' + - 'traefik.http.services.whoami.loadbalancer.server.port=80' + networks: + - home + + ghost: + image: 'ghost:latest' + environment: + url: http://localhost/ghost + labels: + - 'traefik.enable=true' + - 'traefik.http.routers.ghost.rule=PathPrefix(`/ghost{regex:$$|/.*}`)' + - 'traefik.http.services.ghost.loadbalancer.server.port=2368' + networks: + - home + +networks: + home: + external: true \ No newline at end of file diff --git a/docker-compose.traefik.yml b/docker-compose.traefik.yml new file mode 100644 index 0000000..e4df286 --- /dev/null +++ b/docker-compose.traefik.yml @@ -0,0 +1,26 @@ +version: '3.4' +services: + traefik: + image: 'traefik:latest' + ports: + - '80:80' + - '8080:8080' + volumes: + - './traefik.yml:/etc/traefik/traefik.yml' + - '/var/run/docker.sock:/var/run/docker.sock:ro' + + whoami: + image: 'traefik/whoami' + labels: + - 'traefik.enable=true' + - 'traefik.http.routers.whoami.rule=PathPrefix(`/whoami{regex:$$|/.*}`)' + - 'traefik.http.services.whoami.loadbalancer.server.port=80' + + ghost: + image: 'ghost:latest' + environment: + url: http://localhost/ghost + labels: + - 'traefik.enable=true' + - 'traefik.http.routers.ghost.rule=PathPrefix(`/ghost{regex:$$|/.*}`)' + - 'traefik.http.services.ghost.loadbalancer.server.port=2368' \ No newline at end of file diff --git a/traefik.yml b/traefik.yml new file mode 100644 index 0000000..8ca6864 --- /dev/null +++ b/traefik.yml @@ -0,0 +1,10 @@ +## traefik.yml + +# Docker configuration backend +providers: + docker: + defaultRule: "Host(`{{ trimPrefix `/` .Name }}.docker.localhost`)" + +# API and dashboard configuration +api: + insecure: true \ No newline at end of file