cookiecutter-django/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml

109 lines
2.7 KiB
YAML
Raw Normal View History

2019-11-28 23:16:06 +03:00
log:
level: INFO
entryPoints:
web:
# http
address: ':80'
http:
# https://doc.traefik.io/traefik/routing/entrypoints/#entrypoint
redirections:
entryPoint:
to: web-secure
2019-11-28 23:16:06 +03:00
web-secure:
# https
address: ':443'
{%- if cookiecutter.use_celery == 'y' %}
2019-11-28 23:16:06 +03:00
2020-02-04 16:04:47 +03:00
flower:
address: ':5555'
{%- endif %}
2020-02-04 16:04:47 +03:00
2019-11-28 23:16:06 +03:00
certificatesResolvers:
letsencrypt:
# https://doc.traefik.io/traefik/https/acme/#lets-encrypt
2019-11-28 23:16:06 +03:00
acme:
email: '{{ cookiecutter.email }}'
2019-11-28 23:16:06 +03:00
storage: /etc/traefik/acme/acme.json
# https://doc.traefik.io/traefik/https/acme/#httpchallenge
2019-11-28 23:16:06 +03:00
httpChallenge:
entryPoint: web
http:
routers:
web-secure-router:
{%- if cookiecutter.domain_name.count('.') == 1 %}
rule: 'Host(`{{ cookiecutter.domain_name }}`) || Host(`www.{{ cookiecutter.domain_name }}`)'
2021-03-03 01:50:28 +03:00
{%- else %}
rule: 'Host(`{{ cookiecutter.domain_name }}`)'
{%- endif %}
2019-11-28 23:16:06 +03:00
entryPoints:
- web-secure
middlewares:
- csrf
service: django
tls:
# https://doc.traefik.io/traefik/routing/routers/#certresolver
2019-11-28 23:16:06 +03:00
certResolver: letsencrypt
{%- if cookiecutter.use_celery == 'y' %}
2019-11-28 23:16:06 +03:00
2020-02-04 16:04:47 +03:00
flower-secure-router:
rule: 'Host(`{{ cookiecutter.domain_name }}`)'
2020-02-04 16:04:47 +03:00
entryPoints:
- flower
service: flower
tls:
# https://doc.traefik.io/traefik/master/routing/routers/#certresolver
2020-02-04 16:04:47 +03:00
certResolver: letsencrypt
{%- endif %}
{%- if cookiecutter.cloud_provider == 'None' %}
web-media-router:
{%- if cookiecutter.domain_name.count('.') == 1 %}
rule: '(Host(`{{ cookiecutter.domain_name }}`) || Host(`www.{{ cookiecutter.domain_name }}`)) && PathPrefix(`/media/`)'
{%- else %}
rule: 'Host(`{{ cookiecutter.domain_name }}`) && PathPrefix(`/media/`)'
{%- endif %}
entryPoints:
- web-secure
middlewares:
- csrf
service: django-media
tls:
certResolver: letsencrypt
{%- endif %}
2020-02-04 16:04:47 +03:00
2019-11-28 23:16:06 +03:00
middlewares:
csrf:
# https://doc.traefik.io/traefik/master/middlewares/http/headers/#hostsproxyheaders
2019-11-28 23:16:06 +03:00
# https://docs.djangoproject.com/en/dev/ref/csrf/#ajax
headers:
hostsProxyHeaders: ['X-CSRFToken']
2019-11-28 23:16:06 +03:00
services:
django:
loadBalancer:
servers:
- url: http://django:5000
{%- if cookiecutter.use_celery == 'y' %}
2019-11-28 23:16:06 +03:00
2020-02-04 16:04:47 +03:00
flower:
loadBalancer:
servers:
- url: http://flower:5555
{%- endif %}
{%- if cookiecutter.cloud_provider == 'None' %}
django-media:
loadBalancer:
servers:
- url: http://nginx:80
{%- endif %}
2020-02-04 16:04:47 +03:00
2019-11-28 23:16:06 +03:00
providers:
# https://doc.traefik.io/traefik/master/providers/file/
2019-11-28 23:16:06 +03:00
file:
filename: /etc/traefik/traefik.yml
watch: true