GithubHelp home page GithubHelp logo

traefik's Introduction

traefik-host

A simple configuration for running Traefik as a reverse proxy for other docker containers in a home lab. Also gives the benefit of easy setup and automatic renewal of Let's Encrypt certificates, for both domain and subdomains.

Prerequisite:

  • You have access to a FQDN
  • Subdomains have been added to the FQDN DNS and is active
  • Docker and docker-compose is installed
  • Ports 80, 8080 and 443 are portforwarded in your network, and FQDN DNS points to your public IP
  • Ports are available, and not in use by some other software

Note: If you do not have a FQDN, you can remove port 443 from the configuration files and comment out the [acme] block from traefik.toml. This will however limit you to using unecrypted traffic over HTTP.

How to use:

  • Clone repository
  • Update traefik.toml with your email, domain and subdomain information for Let's Encrypt certification issuing
  • Set the correct permissions for the acme.json file
chmod 600 acme.json
  • Create a docker network that will be used for reverse proxy across docker containers:
docker network create web
  • Start the docker container
docker-compose up -d

Example usage:

Here is a working docker-compose.yml example from my simple-portfolio project, which is running Nginx and PHP-FPM:

version: "3.2"                                                                                                                                                                                                 
                                                                                                                                                                                                               
networks:                                                                                                                                                                                                      
  web:                                                                                                                                                                                                         
    external: true    # Traefik reverse proxy network                                                                                                                                                                                           
  internal:                                                                                                                                                                                                    
    external: false   # Internal only network for PHP-FPM                                                                                                                                                                                      
                                                                                                                                                                                                               
services:                                                                                                                                                                                                                                                                                                                                                                                                      
  nginx:                                                                                                                                                                                                       
    image: nginx:${NGINX_VERSION}                                                                                                                                                                              
    networks:                                                                                                                                                                                                  
      - web                                                                                                                                                                                                    
      - internal                                                                                                                                                                                               
    links:                                                                                                                                                                                                     
      - php                                                                                                                                                                                                    
    volumes:                                                                                                                                                                                                   
      - ${PUBLIC_HTML}/:/var/www/html/                                                                                                                                                                         
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf                                                                                                                                             
    depends_on:                                                                                                                                                                                                
      - php                                                                                                                                                                            
    container_name: nginx                                                                                                                                                                                  
    labels:                                                                                                                                                                                                    
      - traefik.enable=true               # Enable Traefik for this container                                                                                                                                                                                    
      - traefik.backend=subdomain         # (Optional) Describe the backend for Traefik                                                                                                                                                                          
      - traefik.frontend.rule=Host:subdomain.yourdomain.com  # The FQDN                                                                                                                                                         
      - traefik.docker.network=web        # The network used for Traefik reverse proxy                                                                                                                                                                           
      - traefik.port=80                   # The port you wish to forward to Traefik                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                                                                                                       
  php:                                                                                                                                                                                                         
    build:                                                                                                                                                                                                     
      context: './docker/php'                                                                                                                                                                                  
      args:                                                                                                                                                                                                    
        PHP_VERSION: ${PHP_VERSION}
    networks:
      - internal
    volumes:
      - ${PUBLIC_HTML}/:/var/www/html/
    container_name: php
    labels:
      - traefik.enable=false        # Disable Traefik, since this is a container for backend stuff

traefik's People

Contributors

frealmyr avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.