# Use domain and not subdomain with docker/traefik to publish an apache webserver to the internet

**URL:** <https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [March 29, 2023, 1:41pm UTC](https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086 "2023-03-29T13:41:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arguably8954](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Arguably8954](https://community.traefik.io/u/Arguably8954)\
**Post date:** [March 29, 2023, 1:41pm UTC](https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086/1 "2023-03-29T13:41:09Z")

</div>

New here and first time posting.

I am struggling to publish an apache website in docker to the internet when using the main domain name "[example.com](http://example.com)", every time I try I get 404 page not found. When using anything before the "[example.com](http://example.com)" it works for example "[abc.example.com](http://abc.example.com)" will work but.

I am using Cloudflare to get wildcard certificates.

**traefik/portainer docker-compose.yml**

```yaml
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="API_EMAIL"
      - CF_DNS_API_TOKEN="API_TOKEN"      
     # be sure to use the correct one depending on if you are using a token or key
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /root/docker/traefik/data/traefik.yml:/traefik.yml:ro
      - /root/docker/traefik/data/acme.json:/acme.json
      - /root/docker/traefik/data/config.yml:/config.yml:ro
      - /root/docker/traefik/logs:/var/log
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.entrypoints=http"
      - "traefik.http.routers.traefik.rule=Host(`traefik-dashboard.example.com`)"
      - "traefik.http.middlewares.traefik-auth.basicauth.users=user123:Hash_Password"
      - "traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https"
      - "traefik.http.routers.traefik.middlewares=traefik-https-redirect"
      - "traefik.http.routers.traefik-secure.entrypoints=https"
      - "traefik.http.routers.traefik-secure.rule=Host(`traefik-dashboard.example.com`)"
      - "traefik.http.routers.traefik-secure.middlewares=traefik-auth"
      - "traefik.http.routers.traefik-secure.tls=true"
      - "traefik.http.routers.traefik-secure.tls.certresolver=cloudflare"
      - "traefik.http.routers.traefik-secure.tls.domains[0].main=example.com"
      - "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.example.com"
      - "traefik.http.routers.traefik-secure.service=api@internal"
  portainer:
    image: portainer/portainer-ce
    container_name: portainer
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    networks:
      - proxy
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /home/username/portainer/data:/data
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.portainer.entrypoints=http"
      - "traefik.http.routers.portainer.rule=Host(`portainer.example.com`)"
      - "traefik.http.middlewares.portainer-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.portainer.middlewares=portainer-https-redirect"
      - "traefik.http.routers.portainer-secure.entrypoints=https"
      - "traefik.http.routers.portainer-secure.rule=Host(`portainer.example.com`)"
      - "traefik.http.routers.portainer-secure.tls=true"
      - "traefik.http.routers.portainer-secure.service=portainer"
      - "traefik.http.services.portainer.loadbalancer.server.port=9000"
      - "traefik.docker.network=proxy"

networks:
  proxy:
    external: true

```

**traefik.yml conf file**

```yaml
api:
  dashboard: true
  debug: true
entryPoints:
  http:
    address: ":80"
    http:
      redirections:
        entryPoint:
          to: https
          scheme: https
  https:
    address: ":443"
serversTransport:
  insecureSkipVerify: true
providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
  file:
    filename: /config.yml
certificatesResolvers:
  cloudflare:
    acme:
      email: me@example.com
      storage: acme.json
      dnsChallenge:
        provider: cloudflare
        #disablePropagationCheck: true # uncomment this if you have issues pulling certificates through cloudflare, By setting this flag to true disables the need to wait for the propagation of the TXT record to all authoritative name servers.
        resolvers:
          - "1.1.1.1:53"
          - "1.0.0.1:53"
log:
  filePath: "/var/log/traefik.log"
  level: DEBUG

```

**apache/php/mysql docker-compose.yml**

```yaml
version: '2.1'
services:
  legacy-php:
    hostname: php
    build: ./php
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    depends_on:
      - db
    networks:
      - proxy
    volumes:
      - "./php/conf.d/00-ioncube.ini:/usr/local/etc/php/conf.d/00-ioncube.ini"
      - "./php/conf.d/99-custom.ini:/usr/local/etc/php/conf.d/99-custom.ini"
      - "./php/home/.bash_aliases:/root/.bash_aliases"
      - "./php/home/.bash_git:/root/.bash_git"
      - "./php/home/.bash_profile:/root/.bash_profile"
      - "./php/home/.bashrc:/root/.bashrc"
      - "./php/home/.git-completion.bash:/root/.git-completion.bash"
      - "./php/home/.git-prompt.sh:/root/.git-prompt.sh"
      - "./php/home/.vimrc:/root/.vimrc"
      - "./htdocs:/var/www/html"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.nginx.entrypoints=http"
      - "traefik.http.routers.nginx.rule=Host(`example.com`, `www.example.com)"
      - "traefik.http.middlewares.nginx-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.nginx.middlewares=nginx-https-redirect"
      - "traefik.http.routers.nginx-secure.entrypoints=https"
      - "traefik.http.routers.nginx-secure.rule=Host(`example.com`)"
      - "traefik.http.routers.nginx-secure.tls=true"
      - "traefik.http.routers.nginx-secure.service=nginx"
      - "traefik.http.services.nginx.loadbalancer.server.port=80"
      - "traefik.docker.network=proxy"
  db:
    image: mysql:5.6
    restart: unless-stopped
    networks:
      - proxy
    environment:
      MYSQL_ROOT_PASSWORD: toor
      MYSQL_USER: user
      MYSQL_PASSWORD: admin
      MYSQL_DATABASE: database
    volumes:
      - ./mysql/conf.d/custom.cnf:/etc/mysql/conf.d/custom.cnf
      - ./mysql/data:/var/lib/mysql:rw
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - "8181:3306"

networks:
  proxy:
    external: true

```

---

<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 29, 2023, 5:50pm UTC](https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086/2 "2023-03-29T17:50:46Z")

</div>

I think you missed to assign your certresolver either to the static entrypoint or to the dynamic router.

---

<div class="post-metadata">

**Author:** ![Arguably8954](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Arguably8954](https://community.traefik.io/u/Arguably8954)\
**Post date:** [March 29, 2023, 7:28pm UTC](https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086/3 "2023-03-29T19:28:40Z")

</div>

How would I properly assign my certresolver?  
The way it is now is I have this line - "traefik.http.routers.traefik-secure.tls.certresolver=cloudflare" in my docker-compose file for traefik.

---

<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 30, 2023, 4:34am UTC](https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086/4 "2023-03-30T04:34:36Z")

</div>

That’s correct, but just for the router

> [@Arguably8954](#):
>
> `traefik-dashboard.example.com`

You also need it for `nginx-secure`.

---

<div class="post-metadata">

**Author:** ![Arguably8954](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Arguably8954](https://community.traefik.io/u/Arguably8954)\
**Post date:** [March 30, 2023, 8:42am UTC](https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086/5 "2023-03-30T08:42:41Z")

</div>

I have tried it with this config.  
But it didn't work. What am I missing?

```yaml
version: '2.1'
services:
  legacy-php:
    hostname: php
    build: ./php
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    depends_on:
      - db
    networks:
      - proxy
    volumes:
      - "./php/conf.d/00-ioncube.ini:/usr/local/etc/php/conf.d/00-ioncube.ini"
      - "./php/conf.d/99-custom.ini:/usr/local/etc/php/conf.d/99-custom.ini"
      - "./php/home/.bash_aliases:/root/.bash_aliases"
      - "./php/home/.bash_git:/root/.bash_git"
      - "./php/home/.bash_profile:/root/.bash_profile"
      - "./php/home/.bashrc:/root/.bashrc"
      - "./php/home/.git-completion.bash:/root/.git-completion.bash"
      - "./php/home/.git-prompt.sh:/root/.git-prompt.sh"
      - "./php/home/.vimrc:/root/.vimrc"
      - "./htdocs:/var/www/html"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.apache.entrypoints=http"
      - "traefik.http.routers.apache.rule=Host(`example.com`)"
      - "traefik.http.middlewares.apache-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.apache.middlewares=apache-https-redirect"
      - "traefik.http.routers.apache-secure.entrypoints=https"
      - "traefik.http.routers.apache-secure.rule=Host(`example.com`)"
      - "traefik.http.routers.apache-secure.tls=true"
      - "traefik.http.routers.apache-secure.tls.certresolver=cloudflare"
      - "traefik.http.routers.apache-secure.service=apache"
      - "traefik.http.services.apache.loadbalancer.server.port=80"
      - "traefik.docker.network=proxy"
  db:
    image: mysql:5.6
    restart: unless-stopped
    networks:
      - proxy
    environment:
      MYSQL_ROOT_PASSWORD: toor
      MYSQL_USER: user
      MYSQL_PASSWORD: admin
      MYSQL_DATABASE: database
    volumes:
      - ./mysql/conf.d/custom.cnf:/etc/mysql/conf.d/custom.cnf
      - ./mysql/data:/var/lib/mysql:rw
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - "8181:3306"

networks:
  proxy:
    external: true

```

---

<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 30, 2023, 10:46am UTC](https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086/6 "2023-03-30T10:46:36Z")

</div>

To reduce config, maybe just move it to the global level:

```auto
entryPoints:
  http:
    address: ":80"
    http:
      redirections:
        entryPoint:
          to: https
          scheme: https
  https:
    address: ":443"
    http:
      tls:
        certResolver: cloudflare

```

You also don't need the redirect middleware in labels, as you have it on a global level already.

---

<div class="post-metadata">

**Author:** ![Arguably8954](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Arguably8954](https://community.traefik.io/u/Arguably8954)\
**Post date:** [March 30, 2023, 11:40am UTC](https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086/7 "2023-03-30T11:40:55Z")

</div>

These are my files  
**apache/mysql docker-compose.yaml**

```yaml
version: '2.1'
services:
  legacy-php:
    hostname: php
    build: ./php
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    depends_on:
      - db
    networks:
      - proxy
    volumes:
      - "./php/conf.d/00-ioncube.ini:/usr/local/etc/php/conf.d/00-ioncube.ini"
      - "./php/conf.d/99-custom.ini:/usr/local/etc/php/conf.d/99-custom.ini"
      - "./php/home/.bash_aliases:/root/.bash_aliases"
      - "./php/home/.bash_git:/root/.bash_git"
      - "./php/home/.bash_profile:/root/.bash_profile"
      - "./php/home/.bashrc:/root/.bashrc"
      - "./php/home/.git-completion.bash:/root/.git-completion.bash"
      - "./php/home/.git-prompt.sh:/root/.git-prompt.sh"
      - "./php/home/.vimrc:/root/.vimrc"
      - "./htdocs:/var/www/html"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.apache.entrypoints=http"
      - "traefik.http.routers.apache.rule=Host(`example.com`)"
      - "traefik.http.routers.apache-secure.entrypoints=https"
      - "traefik.http.routers.apache-secure.rule=Host(`example.com`)"
      - "traefik.http.routers.apache-secure.tls=true"
      - "traefik.http.routers.apache-secure.service=apache"
      - "traefik.http.services.apache.loadbalancer.server.port=80"
      - "traefik.docker.network=proxy"
  db:
    image: mysql:5.6
    restart: unless-stopped
    networks:
      - proxy
    environment:
      MYSQL_ROOT_PASSWORD: toor
      MYSQL_USER: user
      MYSQL_PASSWORD: admin
      MYSQL_DATABASE: database
    volumes:
      - ./mysql/conf.d/custom.cnf:/etc/mysql/conf.d/custom.cnf
      - ./mysql/data:/var/lib/mysql:rw
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - "8181:3306"

networks:
  proxy:
    external: true

```

**Traefik/portainer docker-compose.yaml**

```yaml
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=pits-blazers-0c@icloud.com
      - CF_DNS_API_TOKEN=JbIrYkbksXtM8_uFg9i5jHnz_-nd-3AGICFTZBLM
      #- CF_DNS_API_TOKEN=x6IFl0XG9WIdUWKsad3IXNAlHuRcVOw11VpWH2IJ
      #- CF_API_KEY=f16348bf50f68397286b5ffb01168407abe56
      # be sure to use the correct one depending on if you are using a token or key
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /root/docker/traefik/data/traefik.yml:/traefik.yml:ro
      - /root/docker/traefik/data/acme.json:/acme.json
      - /root/docker/traefik/data/config.yml:/config.yml:ro
      - /root/docker/traefik/logs:/var/log
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.entrypoints=http"
      - "traefik.http.routers.traefik.rule=Host(`traefik-dashboard.example.com`)"
      - "traefik.http.middlewares.traefik-auth.basicauth.users=user:password"
      - "traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https"
      - "traefik.http.routers.traefik.middlewares=traefik-https-redirect"
      - "traefik.http.routers.traefik-secure.entrypoints=https"
      - "traefik.http.routers.traefik-secure.rule=Host(`traefik-dashboard.example.com`)"
      - "traefik.http.routers.traefik-secure.middlewares=traefik-auth"
      - "traefik.http.routers.traefik-secure.tls=true"
      - "traefik.http.routers.traefik-secure.tls.domains[0].main=example.com"
      - "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.example.com"
      - "traefik.http.routers.traefik-secure.service=api@internal"
  portainer:
    image: portainer/portainer-ce
    container_name: portainer
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    networks:
      - proxy
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /home/username/portainer/data:/data
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.portainer.entrypoints=http"
      - "traefik.http.routers.portainer.rule=Host(`portainer.example.com`)"
      - "traefik.http.middlewares.portainer-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.portainer.middlewares=portainer-https-redirect"
      - "traefik.http.routers.portainer-secure.entrypoints=https"
      - "traefik.http.routers.portainer-secure.rule=Host(`portainer.example.com`)"
      - "traefik.http.routers.portainer-secure.tls=true"
      - "traefik.http.routers.portainer-secure.service=portainer"
      - "traefik.http.services.portainer.loadbalancer.server.port=9000"
      - "traefik.docker.network=proxy"

networks:
  proxy:
    external: true

```

**traefik.yml**

```yaml
api:
  dashboard: true
  debug: true
entryPoints:
  http:
    address: ":80"
    http:
      redirections:
        entryPoint:
          to: https
          scheme: https
  https:
    address: ":443"
    http:
      tls:
        certResolver: cloudflare
serversTransport:
  insecureSkipVerify: true
providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
  file:
    filename: /config.yml
certificatesResolvers:
  cloudflare:
    acme:
      email: name@me.com
      storage: acme.json
      dnsChallenge:
        provider: cloudflare
        #disablePropagationCheck: true # uncomment this if you have issues pulling certificates through cloudflare, By setting this flag to true disables the need to wait for the propagation of the TXT record to all authoritative name servers.
        resolvers:
          - "1.1.1.1:53"
          - "1.0.0.1:53"
log:
  filePath: "/var/log/traefik.log"
  level: DEBUG

```

Stil getting 404 page not found on [example.com](http://example.com). [traefik-dashboard.example.com](http://traefik-dashboard.example.com) and [portainer.example.com](http://portainer.example.com) work fine.  
Extra note when surfing to [example.com](http://example.com) I get 404 page not found put the certificate works.  
Yesterday I also tried another domain name that I own lets call it "[homelab.com](http://homelab.com)" and this domain name worked instead of "[example.com](http://example.com)". Don't know if you can do anything with this info.

---

<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 30, 2023, 4:08pm UTC](https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086/8 "2023-03-30T16:08:26Z")

</div>

What does Traefik Dashboard tell you?

Maybe up your compose file version to 3.

Remove not needed labels:

```auto
 - "traefik.http.routers.apache.entrypoints=http"
 - "traefik.http.routers.apache.rule=Host(`example.com`)"

```

---

<div class="post-metadata">

**Author:** ![Arguably8954](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Arguably8954](https://community.traefik.io/u/Arguably8954)\
**Post date:** [April 3, 2023, 3:15pm UTC](https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086/9 "2023-04-03T15:15:45Z")

</div>

I fixed my issue by changing this line:

```yaml
      - "traefik.http.routers.apache.rule=Host(`example.com`)"

```

into this:

```yaml
      - "traefik.http.routers.apache.rule=Host(`example.com, `www.example.com`)"

```

But really appreciated the help, found out a lot more about traefik with your expertise.

---

<div class="post-metadata">

**Author:** ![rlimaeco](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/rlimaeco/32/7726_2.png) [@rlimaeco](https://community.traefik.io/u/rlimaeco)\
**Post date:** [October 18, 2023, 11:03pm UTC](https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086/10 "2023-10-18T23:03:03Z")

</div>

You saved my week ! thanks a lot !

---

<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:** [October 19, 2023, 5:45am UTC](https://community.traefik.io/t/use-domain-and-not-subdomain-with-docker-traefik-to-publish-an-apache-webserver-to-the-internet/18086/11 "2023-10-19T05:45:31Z")

</div>

Traefik v3 will only accept a single domain in `Host()`, so you can already prepare by using

```auto
Host(`example.com`) || Host(`www.example.com`)

```
