title: Configuring Nginx with Traefik
body: <p>I'm new to Linux in general, and even newer to Traefik, and have been trying for some time to setup a nginx container to serve some AngularJS web pages, using Traefik as reverse-proxy. I have a small Ubuntu 20.4 server hosted on DigitalOcean (if that's of any relevance).</p>
  <p>I have tried following a few different nginx tutorials, and messing with the settings on my own, to no success. It works if I run a simple command like:</p>
  <blockquote>
  <p>$ docker run –name some-nginx -d -p 8888:80 nginx</p>
  </blockquote>
  <p>But then I can only access it through myip:8888, and I would like to access it with a subdomain, i.e. docs.domain.com.</p>
  <p>I managed to setup Traefik using a traefik.yml like that:</p>
  <pre><code>api:
    dashboard: true
  
  entryPoints:
    http:
      address: &quot;:80&quot;
    https:
      address: &quot;:443&quot;
  
  providers:
    docker:
      endpoint: &quot;unix:///var/run/docker.sock&quot;
      exposedByDefault: false
  
  certificatesResolvers:
    http:
      acme:
        email: email@email.com
        storage: acme.json
        httpChallenge:
          entryPoint: http
  </code></pre>
  <p>And then docker-compose this file:</p>
  <pre><code>version: '3'
  
  services:
    traefik:
      image: traefik:v2.0
      container_name: traefik
      restart: unless-stopped
      security_opt:
        - no-new-privileges:true
      networks:
        - proxy
      ports:
        - 80:80
        - 443:443
      volumes:
        - /etc/localtime:/etc/localtime:ro
        - /var/run/docker.sock:/var/run/docker.sock:ro
        - ./traefik.yml:/traefik.yml:ro
        - ./acme.json:/acme.json
      labels:
        - &quot;traefik.enable=true&quot;
        - &quot;traefik.http.routers.traefik.entrypoints=http&quot;
        - &quot;traefik.http.routers.traefik.rule=Host(`monitor.domain.com`)&quot;
        - &quot;traefik.http.middlewares.traefik-auth.basicauth.users=admin:secret_password&quot;
        - &quot;traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https&quot;
        - &quot;traefik.http.routers.traefik.middlewares=traefik-https-redirect&quot;
        - &quot;traefik.http.routers.traefik-secure.entrypoints=https&quot;
        - &quot;traefik.http.routers.traefik-secure.rule=Host(`monitor.domain.com`)&quot;
        - &quot;traefik.http.routers.traefik-secure.middlewares=traefik-auth&quot;
        - &quot;traefik.http.routers.traefik-secure.tls=true&quot;
        - &quot;traefik.http.routers.traefik-secure.tls.certresolver=http&quot;
        - &quot;traefik.http.routers.traefik-secure.service=api@internal&quot;
  
  networks:
    proxy:
      external: true
  </code></pre>
  <p>I also successfully set up a portainer:</p>
  <pre><code>version: '3'
  
  services:
    portainer:
      image: portainer/portainer:latest
      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
        - ./data:/data
      labels:
        - &quot;traefik.enable=true&quot;
        - &quot;traefik.http.routers.portainer.entrypoints=http&quot;
        - &quot;traefik.http.routers.portainer.rule=Host(`manage.domain.com`)&quot;
        - &quot;traefik.http.middlewares.portainer-https-redirect.redirectscheme.scheme=https&quot;
        - &quot;traefik.http.routers.portainer.middlewares=portainer-https-redirect&quot;
        - &quot;traefik.http.routers.portainer-secure.entrypoints=https&quot;
        - &quot;traefik.http.routers.portainer-secure.rule=Host(`manage.domain.com`)&quot;
        - &quot;traefik.http.routers.portainer-secure.tls=true&quot;
        - &quot;traefik.http.routers.portainer-secure.tls.certresolver=http&quot;
        - &quot;traefik.http.routers.portainer-secure.service=portainer&quot;
        - &quot;traefik.http.services.portainer.loadbalancer.server.port=9000&quot;
        - &quot;traefik.docker.network=proxy&quot;
  
  networks:
    proxy:
      external: true
  </code></pre>
  <p>This way I can access both portainer and traefik subdomains, with SSL, no problems.</p>
  <p>I tried using docker-compose files for nginx similar to the portainer one, using the volumes &quot;./data:/usr/share/nginx/html:ro&quot; and &quot;./nginx.conf:/etc/nginx/nginx.conf:ro&quot;, as well some different nginx.conf options as exemplified in the <a href="http://nginx.org/en/docs/beginners_guide.html#conf_structure" rel="nofollow noreferrer">Beginner's Guide</a> from the official docs.
  I would appreciate if someone could point ou which labels I should use on the docker-compose file and how to properly interface Traefik with the nginx config.</p>