簡體   English   中英

如何配置Traefik使用Django Sites Framework

[英]How to configure Traefik to use Django Sites Framework

我正在使用Docker-compose和Traefik與Let'sencrypt在生產中測試cookiecutter-django 我正在嘗試使用Django站點將其配置為使用2個域(mydomain1.com和mydomain2.com)。

如何配置Traefik以便它可以將流量轉發到必要的域?

這是我的traefik.toml

logLevel = "INFO"
defaultEntryPoints = ["http", "https"]

# Entrypoints, http and https
[entryPoints]
  # http should be redirected to https
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
    entryPoint = "https"
  # https is the default
  [entryPoints.https]
  address = ":443"
    [entryPoints.https.tls]

# Enable ACME (Let's Encrypt): automatic SSL
[acme]
# Email address used for registration
email = "mail@mydomain1.com"
storage = "/etc/traefik/acme/acme.json"
entryPoint = "https"
onDemand = false
OnHostRule = true
  # Use a HTTP-01 acme challenge rather than TLS-SNI-01 challenge
  [acme.httpChallenge]
  entryPoint = "http"

[file]
[backends]
  [backends.django]
    [backends.django.servers.server1]
      url = "http://django:5000"

[frontends]
  [frontends.django]
    backend = "django"
    passHostHeader = true
    [frontends.django.headers]
      HostsProxyHeaders = ['X-CSRFToken']
    [frontends.django.routes.dr1]
      rule = "Host:mydomain1.com"

現在所有域都通過ssl工作,但我只能看到mydomain1.com,mydomain2.com顯示ERR_TOO_MANY_REDIRECTS。

你有什么嘗試? 什么不起作用? 通過閱讀你的問題,很難說。

在cc-django repo中您似乎已經打開的問題中有一個答案元素。

首先,我會嘗試將Traefik排除在等式之外,並按照建議做一些事情,讓本地工作。 一旦它在本地工作,就需要將正確的端口/容器映射到Traefik中的正確域。

假設您已配置docker-compose以在端口5000和5001上運行django容器,我認為您需要調整后端和前端部分,如下所示:

[backends]
  [backends.django1]
    [backends.django1.servers.server1]
      url = "http://django:5000"
  [backends.django2]
    [backends.django2.servers.server1]
      url = "http://django:5001"

[frontends]
  [frontends.django1]
    backend = "django1"
    passHostHeader = true
    [frontends.django1.headers]
      HostsProxyHeaders = ['X-CSRFToken']
    [frontends.django1.routes.dr1]
      rule = "Host:mydomain1.com"
  [frontends.django2]
    backend = "django2"
    passHostHeader = true
    [frontends.django2.headers]
      HostsProxyHeaders = ['X-CSRFToken']
    [frontends.django2.routes.dr1]
      rule = "Host:mydomain2.com"

我沒試過這些,但那是我要做的第一件事。 此外,看起來我們可以在前端指定規則來調整路由。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM