Last active
October 7, 2021 11:45
-
-
Save stepankuzmin/a5b268231db1d470580cad9086def335 to your computer and use it in GitHub Desktop.
traefik docker-compose example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user nginx; | |
worker_processes auto; | |
worker_cpu_affinity auto; | |
pid /run/nginx.pid; | |
events { | |
worker_connections 4086; | |
use epoll; | |
multi_accept on; | |
} | |
http { | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
keepalive_timeout 65; | |
keepalive_requests 1000; | |
types_hash_max_size 2048; | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
types { | |
application/vnd.geo+json geojson; | |
} | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log; | |
gzip on; | |
gzip_vary on; | |
gzip_proxied any; | |
gzip_comp_level 6; | |
gzip_buffers 16 8k; | |
gzip_http_version 1.1; | |
gzip_min_length 256; | |
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml | |
application/javascript application/json application/x-protobuf application/vnd.geo+json; | |
proxy_cache_path /var/cache/nginx/ | |
levels=1:2 | |
max_size=10g | |
inactive=60m | |
use_temp_path=off | |
keys_zone=backend_cache:10m; | |
upstream martin_upstream { | |
server tiles:3000; | |
} | |
server { | |
listen 80; | |
server_name localhost; | |
resolver 127.0.0.11; | |
location ~ /martin/(?<fwd_path>.*) { | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Host $host; | |
proxy_set_header X-Rewrite-URL $request_uri; | |
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto; | |
proxy_redirect off; | |
proxy_connect_timeout 15m; | |
proxy_send_timeout 15m; | |
proxy_read_timeout 15m; | |
send_timeout 15m; | |
proxy_cache backend_cache; | |
proxy_cache_lock on; | |
proxy_cache_revalidate on; | |
proxy_cache_valid 200 204 302 1y; | |
proxy_cache_valid 404 1m; | |
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504; | |
add_header X-Cache-Status $upstream_cache_status; | |
proxy_pass http://martin_upstream/$fwd_path$is_args$args; | |
} | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /usr/share/nginx/html; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.7" | |
services: | |
traefik: | |
image: traefik:1.7-alpine | |
container_name: traefik | |
restart: always | |
ports: | |
- 80:80 | |
- 443:443 | |
volumes: | |
- ./traefik:/etc/traefik:Z | |
- /var/run/docker.sock:/var/run/docker.sock | |
command: | |
- --entrypoints=Name:http Address::80 Redirect.EntryPoint:https | |
- --entrypoints=Name:https Address::443 TLS | |
- --defaultentrypoints=http,https | |
- --acme | |
- --acme.email=${ACME_EMAIL} | |
- --acme.storage=/etc/traefik/acme.json | |
- --acme.entryPoint=https | |
- --acme.httpChallenge.entryPoint=http | |
- --acme.OnHostRule=true | |
- --acme.onDemand=false | |
- --acme.acmeLogging=true | |
- --web | |
- --docker | |
- --docker.watch | |
- --docker.exposedbydefault=false | |
- --docker.domain=${DOCKER_DOMAIN} | |
networks: | |
- proxy | |
backend: | |
image: nginx:alpine | |
restart: always | |
labels: | |
- traefik.enable=true | |
- traefik.docker.network=proxy | |
- traefik.frontend.rule=Host:${DOCKER_DOMAIN} | |
volumes: | |
- ./nginx.conf:/etc/nginx/conf.d/default.conf | |
networks: | |
proxy: | |
external: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment