# Traefik can retrieve a wildcard certificate for the primary domain, but not a subdomain

**URL:** <https://community.traefik.io/t/traefik-can-retrieve-a-wildcard-certificate-for-the-primary-domain-but-not-a-subdomain/18002>\
**Category:** Traefik v2\
**Tags:** letsencrypt-acme, docker\
**Created:** [March 21, 2023, 8:18pm UTC](https://community.traefik.io/t/traefik-can-retrieve-a-wildcard-certificate-for-the-primary-domain-but-not-a-subdomain/18002 "2023-03-21T20:18:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![trumpet7347](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/trumpet7347/32/6847_2.png) [@trumpet7347](https://community.traefik.io/u/trumpet7347)\
**Post date:** [March 21, 2023, 8:18pm UTC](https://community.traefik.io/t/traefik-can-retrieve-a-wildcard-certificate-for-the-primary-domain-but-not-a-subdomain/18002/1 "2023-03-21T20:18:37Z")

</div>

Hi, I currently have Traefik running on docker, and setup to retrieve certificates from Letsencrypt using Cloudflare as the cert resolver. I am able to successfully get a wild card certificate for my main domain (\*.mydomain.com), but I am unable to get one for a subdomain (\*.local.mydomain.com), but there is also no error in the logs so Im not really sure whats going on. Below are my docker-compose and config files. This setup was working previously, but stopped at some point and I only noticed when I got an email saying my certificates were going to expire. Any help would be greatly appreciated!

Traefik docker-compose:

```auto
version: '3'

services:
  traefik:
    image: traefik:latest
    container_name: traefik
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    networks:
      - proxy
    ports:
      - 80:80
      - 443:443
    environment:
      - CF_API_EMAIL=${CF_API_EMAIL}
      - CF_DNS_API_TOKEN=${CF_DNS_API_TOKEN}
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /home/user/traefik/data/traefik.yml:/traefik.yml:ro
      - /home/user/traefik/data/acme.json:/acme.json
      - /home/user/traefik/data/config.yml:/config.yml:ro
    labels:
      - "traefik.enable=true"
      # https
      - "traefik.http.routers.traefik-secure.tls=true"
      - "traefik.http.routers.traefik-secure.entrypoints=https"
      - "traefik.http.routers.traefik-secure.rule=Host(`traefik.local.mydomain.com`)"
      # wildcard certs
      - "traefik.http.routers.traefik-secure.tls.certresolver=cloudflare"
      - "traefik.http.routers.traefik-secure.tls.domains[0].main=local.mydomain.com"
      - "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.local.mydomain.com"
      - "traefik.http.routers.traefik-secure.tls.domains[0].main=mydomain.com"
      - "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.mydomain.com"
      - "traefik.http.routers.traefik-secure.service=api@internal"
      # global redirect to https
      - "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
      - "traefik.http.routers.http-catchall.entrypoints=http"
      - "traefik.http.routers.http-catchall.middlewares=redirect-to-https"
      # middleware redirect
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"

networks:
  proxy:
    external: true

```

traefik.yml:

```auto
api:
    dashboard: true
    debug: true
  entryPoints:
    http:
      address: ":80"
    https:
      address: ":443"
  serversTransport:
    insecureSkipVerify: true
  providers:
    docker:
      endpoint: "unix:///var/run/docker.sock"
      exposedByDefault: false
    file:
      filename: /config.yml
  certificatesResolvers:
    cloudflare:
      acme:
        email: mycloudflareemail@gmail.com
        storage: acme.json
        dnsChallenge:
          provider: cloudflare
          resolvers:
            - "1.1.1.1:53"
            - "1.0.0.1:53"

```

---

<div class="post-metadata">

**Author:** ![trumpet7347](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/trumpet7347/32/6847_2.png) [@trumpet7347](https://community.traefik.io/u/trumpet7347)\
**Post date:** [March 21, 2023, 9:30pm UTC](https://community.traefik.io/t/traefik-can-retrieve-a-wildcard-certificate-for-the-primary-domain-but-not-a-subdomain/18002/2 "2023-03-21T21:30:29Z")

</div>

Ok, I was able to get the subdomain certificate generated. I ended up commenting out the section in my docker-compose that generated the certificate for the primary domain, while leaving the section for the subdomain uncommented, after restarting Traefik, it immediately generated the certificate for the subdomain. After that I uncommented the lines for the primary domain, and now everything seems to be working. I am not sure why this was the resolution, if anyone has any more insight I would love to learn why.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [March 22, 2023, 6:25am UTC](https://community.traefik.io/t/traefik-can-retrieve-a-wildcard-certificate-for-the-primary-domain-but-not-a-subdomain/18002/3 "2023-03-22T06:25:26Z")

</div>

> [@trumpet7347](#):
>
> ```auto
> - "traefik.http.routers.traefik-secure.tls.domains[0].main=local.mydomain.com"
> - "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.local.mydomain.com"
> - "traefik.http.routers.traefik-secure.tls.domains[0].main=mydomain.com"
> - "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.mydomain.com"
> 
> ```

Should probably be 0, 0, 1, 1 (array index).

---

<div class="post-metadata">

**Author:** ![trumpet7347](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/trumpet7347/32/6847_2.png) [@trumpet7347](https://community.traefik.io/u/trumpet7347)\
**Post date:** [March 29, 2023, 1:34pm UTC](https://community.traefik.io/t/traefik-can-retrieve-a-wildcard-certificate-for-the-primary-domain-but-not-a-subdomain/18002/4 "2023-03-29T13:34:17Z")

</div>

Sorry it took me so long to reply, I have been out of town. I updated the array index and it indeed worked as intended. Thanks bluepuma77!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [April 5, 2023, 1:58pm UTC](https://community.traefik.io/t/traefik-can-retrieve-a-wildcard-certificate-for-the-primary-domain-but-not-a-subdomain/18002/5 "2023-04-05T13:58:06Z")

</div>

Closed on April 5, 2023, 1:58pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
