Giter Site home page Giter Site logo

hartwork / docker-ssl-reverse-proxy Goto Github PK

View Code? Open in Web Editor NEW
24.0 6.0 4.0 41 KB

:lock: Easy-to-use auto-SSL reverse proxy as a Docker container based on Caddy and Let’s Encrypt

Python 61.06% Dockerfile 22.22% Shell 16.72%
docker-image reverse-proxy reverseproxy caddy letsencrypt lets-encrypt python docker-compose python3 python-3

docker-ssl-reverse-proxy's Introduction

About docker-ssl-reverse-proxy

My situation was this: I had multiple Docker containers serving websites on port 80. I wanted a single reverse proxy with SSL powered by Let's Encrypt in front of them that keeps certificates fresh and supports multiple domain names per website (e.g. with www. subdomain and without). Plain HTTP should be redirected to HTTPS on the master domain for each website, alias domains should redirect to the master domain for both HTTP and HTTPS. And that reverse proxy should also run in a Docker container.

This repository has all of that. The heavy lifting is done by Caddy and there's a small tool to generate Caddy configuration from a minimal ini-like sites.cfg file for you (see example).

Thanks to Abiola Ibrahim (@abiosoft) for sharing his Caddy 1.x.x Docker images that I build upon prior to switching to official Caddy 2.x.x Docker images.

Getting Started

  1. Create a simple sites.cfg file manually as seen in the example.

  2. Run ./Caddyfile.generate to generate Caddyfile from sites.cfg for you.

  3. Create Docker network ssl-reverse-proxy for the reverse proxy and its backends to talk:
    docker network create --internal ssl-reverse-proxy

  4. Spin up the container:
    docker-compose up -d --build

  5. Have backend containers join network ssl-reverse-proxy, e.g. as done in the proxy's own docker-compose.yml file.

  6. Enjoy.

How to write the sites.cfg file

The format is rather simple and has three options only. Let's look at this example:

[example.org]
backend = example-org:80
aliases =
    www.example.org
        example.net
    www.example.net

Section name example.org sets the master domain name that all alias domains redirect to. backend points to the hostname and port that serves actual content. Here, example-org is the name of the Docker container that Docker DNS will let us access because we made both containers join external network ssl-reverse-proxy in their docker-compose.yml files. aliases is an optional list of domain names to have both HTTP and HTTPS redirect to master domain example.org. That's it.

The Caddyfile generated from that very sites.cfg would read:

# NOTE: This file has been generated, do not edit
(common) {
    encode zstd gzip
    log {
        output stdout
    }
}

example.org {
    import common
    reverse_proxy example-org:80 {
        header_down +Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
    }
}

example.net {
    import common
    redir https://example.org{uri}
}

www.example.net {
    import common
    redir https://example.org{uri}
}

www.example.org {
    import common
    redir https://example.org{uri}
}

Support and Contributing

If you run into issues or have questions, please open an issue ticket for that.

Please know that sites.cfg and Caddyfile.generate are not meant to cover much more than they already do. If it grows as powerful as Caddyfile we have failed.

docker-ssl-reverse-proxy's People

Contributors

dependabot[bot] avatar hartwork avatar peppelauro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

docker-ssl-reverse-proxy's Issues

Add support for Traefik

If all current features of sites.cfg (alias domains, redirect to HTTPS on main domains) can be covered in a single config file, it would be cool to offer support for https://traefik.io/.

PS: Before anyone starts to work on pull requests, please get in touch offline to talk about vision and details. Thanks!

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.