Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to listen to both www.example.com and example.com? #116

Closed
polds opened this issue Nov 17, 2015 · 13 comments · Fixed by #285
Closed

Possible to listen to both www.example.com and example.com? #116

polds opened this issue Nov 17, 2015 · 13 comments · Fixed by #285

Comments

@polds
Copy link

polds commented Nov 17, 2015

Using the wildcard subdomain you can listen to {subdomain: [a-z]+}.example.com, that however does not also include example.com. Is it possible to listen to both?

@emilevauge
Copy link
Member

@polds, you can add another frontend with Host : example.com, it should work. Can you confirm ?

@rogierlommers
Copy link

I'm also having trouble setting this up. I have a backend defined:

[backends.mysite]
  [backends.mysite.servers.server1]
  url = "http://127.0.0.1:81"

Now I want this backend to be accessable through both mysite.nl and www.mysite.nl. I tried to do this:

[frontends.mysite]
backend = "mysite"
passHostHeader = true
  [frontends.mysite.routes.host1]
  rule = "Host"
  value = "www.mysite.nl"
  [frontends.mysite.routes.host2]
  rule = "Host"
  value = "mysite.nl"

Unfortunately this does not work, both mysite.nl and www.mysite.nl is resolving in HTTP/1.1 404 Not Found. When I remove the 2nd frontend, the first one will work again.

@polds
Copy link
Author

polds commented Nov 18, 2015

@emilevauge Sorry I should have mentioned I'm using the Docker provider so not dealing with frontends.

@emilevauge emilevauge added the bug label Nov 20, 2015
@emilevauge
Copy link
Member

Hi @polds @rogierlommers, it's seems to be a bug :( Will look at it.

@emilevauge emilevauge self-assigned this Nov 20, 2015
@hd-deman
Copy link

same bug with consul provider and file provider.

@hd-deman
Copy link

this is absolutely crazy to create new frontend for each rote, instead of creating routes for one frontend.

@emilevauge
Copy link
Member

And this kind of comment makes me wonder why this project is open source and free to use...

@hd-deman
Copy link

I feel your pain.

@emilevauge
Copy link
Member

I just tested it using docker backend, and it seems to work (on the latest version):

$ docker run -d -l traefik.backend=test -l traefik.frontend.rule=Host -l traefik.frontend.value=docker.localhost emilevauge/whoami
$ docker run -d -l traefik.backend=test -l traefik.frontend.rule=Host -l traefik.frontend.value=test.docker.localhost emilevauge/whoami

$ curl -s http://localhost:8080/api/providers | jq .
{
  "docker": {
    "frontends": {
      "\"frontend-Host-test-docker-localhost\"": {
        "routes": {
          "\"route-frontend-Host-test-docker-localhost\"": {
            "value": "test.docker.localhost",
            "rule": "Host"
          }
        },
        "backend": "backend-test"
      },
      "\"frontend-Host-docker-localhost\"": {
        "routes": {
          "\"route-frontend-Host-docker-localhost\"": {
            "value": "docker.localhost",
            "rule": "Host"
          }
        },
        "backend": "backend-test"
      }
    },
    "backends": {
      "backend-test": {
        "loadBalancer": {
          "method": "wrr"
        },
        "servers": {
          "server-cranky_kalam": {
            "url": "http://172.17.0.3:80"
          },
          "server-admiring_cori": {
            "url": "http://172.17.0.2:80"
          }
        }
      }
    }
  }
}


$ curl http://docker.localhost
Hostname: 538097d25c11
IP: 127.0.0.1
IP: ::1
IP: 172.17.0.3
IP: fe80::42:acff:fe11:3
GET / HTTP/1.1
Host: 172.17.0.3:80
User-Agent: curl/7.35.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 10.0.1.18
X-Forwarded-Host: 172.17.0.3:80
X-Forwarded-Proto: http
X-Forwarded-Server: petiteboite

$ curl http://test.docker.localhost
Hostname: 9fbf1562c1f6
IP: 127.0.0.1
IP: ::1
IP: 172.17.0.2
IP: fe80::42:acff:fe11:2
GET / HTTP/1.1
Host: 172.17.0.2:80
User-Agent: curl/7.35.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 10.0.1.18
X-Forwarded-Host: 172.17.0.2:80
X-Forwarded-Proto: http
X-Forwarded-Server: petiteboite

Using file backend with these rules seems also OK:

  [backends]
    [backends.backend1]
      [backends.backend1.LoadBalancer]
        method = "wrr"
      [backends.backend1.servers.server1]
      url = "http://172.17.0.2:80"
      weight = 1

  [frontends]
    [frontends.frontend1]
    backend = "backend1"
      [frontends.frontend1.routes.test_1]
      rule = "Host"
      value = "localhost"
    [frontends.frontend2]
    backend = "backend1"
      [frontends.frontend2.routes.test_1]
      rule = "Host"
      value = "{subdomain:[a-z]+}.localhost"
$ curl http://localhost
Hostname: 9fbf1562c1f6
IP: 127.0.0.1
IP: ::1
IP: 172.17.0.2
IP: fe80::42:acff:fe11:2
GET / HTTP/1.1
Host: 172.17.0.2:80
User-Agent: curl/7.35.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 127.0.0.1
X-Forwarded-Host: 172.17.0.2:80
X-Forwarded-Proto: http
X-Forwarded-Server: petiteboite

$ curl http://test.localhost
Hostname: 9fbf1562c1f6
IP: 127.0.0.1
IP: ::1
IP: 172.17.0.2
IP: fe80::42:acff:fe11:2
GET / HTTP/1.1
Host: 172.17.0.2:80
User-Agent: curl/7.35.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 10.0.1.18
X-Forwarded-Host: 172.17.0.2:80
X-Forwarded-Proto: http
X-Forwarded-Server: petiteboite

Could you give more info on your conf? Could you test using my exemple?

I know that using multiple frontends to do that is not perfect, but for now, this is a workaround. I'm planning to modify the behavior of routes, now there is a AND operation between routes from a frontend, and I think it would be more useful to have a OR. WDYT?

@hd-deman
Copy link

@emilevauge you example works because you define two frontends:

  [frontends]
    [frontends.frontend1]
    backend = "backend1"
      [frontends.frontend1.routes.test_1]
      rule = "Host"
      value = "localhost"
    [frontends.frontend2]
    backend = "backend1"
      [frontends.frontend2.routes.test_1]
      rule = "Host"
      value = "{subdomain:[a-z]+}.localhost"

But If you define one frontend and two routes for it, it doesn't:

  [frontends]
    [frontends.frontend1]
    backend = "backend1"
      [frontends.frontend1.routes.test_1]
      rule = "Host"
      value = "localhost"
      [frontends.frontend2.routes.test_2]
      rule = "Host"
      value = "{subdomain:[a-z]+}.localhost"

@emilevauge
Copy link
Member

@hd-deman, that's why I said:

I know that using multiple frontends to do that is not perfect, but for now, this is a workaround. I'm planning to modify the behavior of routes, now there is a AND operation between routes from a frontend, and I think it would be more useful to have a OR. WDYT?

@emilevauge
Copy link
Member

@polds, is the issue still there? Because I cannot reproduce it here ;)

@polds
Copy link
Author

polds commented Feb 1, 2016

Yeah if launched twice it works with no issues :)

@emilevauge emilevauge mentioned this issue Apr 6, 2016
2 tasks
@traefik traefik locked and limited conversation to collaborators Sep 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants