在traefik toml文件中设置Access-Control-Allow-Origin

时间:2019-12-13 21:45:52

标签: cors 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 = "eswar0077@gmail.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"

[http.middlewares]
  [http.middlewares.testHeader.headers]
    accessControlAllowMethods= ["GET", "OPTIONS", "PUT"]
    accessControlAllowOrigin = "*"
    accessControlMaxAge = 100
    addVaryHeader = true

[file]
[backends]
  [backends.django]
    [backends.django.servers.server1]
      url = "http://django:5000"
    [backends.stream]
      [backends.stream.servers.server1]
        url = "http://stream.aphdlivestreaming.in:8080"

[frontends]
  [frontends.django]
    backend = "django"
    passHostHeader = true
    [frontends.django.headers]
      HostsProxyHeaders = ['X-CSRFToken']
    [frontends.django.routes.dr1]
      rule = "Host:aphdlivestreaming.in"
  [frontends.stream]
    backend = "stream"
    passHostHeader = true
    [frontends.stream.headers]
      HostsProxyHeaders = ['X-CSRFToken']
      Access-Control-Allow-Origin = "*"
    [frontends.stream.routes.dr1]
      rule = "Host:live.aphdlivestreaming.in"

我想在流前端启用cors,但是它不起作用。遵循官方文档进行了尝试,但没有效果。我不断收到错误“从源'https://live.aphdlivestreaming.in/live/iBNxcSrlvhv119Fc255D/iBNxcSrlvhv119Fc255D.m3u8到'https://aphdlivestreaming.in'对XMLHttpRequest的访问”已被CORS策略阻止:所请求的资源上没有'Access-Control-Allow-Origin'标头”。谁能指导我

0 个答案:

没有答案