Coder Social home page Coder Social logo

kloudtek / docker-haproxy-letsencrypt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tecnativa/docker-haproxy-letsencrypt

1.0 3.0 0.0 50 KB

Dockerized production-ready Plug&Play Let's Encrypt-ed HTTPS proxy

License: Apache License 2.0

Shell 100.00%

docker-haproxy-letsencrypt's Introduction

HTTPS Proxy

Use HAProxy to create a HTTPS proxy with for Let's Encrypt.

To understand settings in configuration files, see online manual.

Disclaimer about load balancing

This container uses HAProxy, but it does not perform load balancing. It's just for adding an HTTPS layer to any HTTP container.

However, feel free to fork or subclass this image to do it, or just use other container for load balancing and link it to this one to add HTTPS to it.

Disclaimer about certificates storage

You should store the /etc/letsencrypt volume contents somewhere persistent and safe. It contains certificates and private keys, and those things are important.

How does it work?

It is based on the officially-supported HAProxy Alpine image with a hash-pinned install of the official ACME client supported by Let's Encrypt and the EFF: Certbot, so it tries to stick to official recommendations as close as possible.

Before booting HAProxy, it uses the provided configuration to get any missing certificates from Let's Encrypt directly using Certbot's standalone http-01 challenge implementation, directly on port 80.

After that, it combines the certificate chain with the private key to satisfy HAProxy's requirements and generates a crt-list file ready for HAProxy's taste.

Finally, it will boot up the server using with configuration from /etc/haproxy/*.cfg.

Skip the boring parts

If you understand the Docker Compose file, then all you need to do is to open docker-compose.yaml, follow any instructions labeled with XXX, and adapt that structure to your project.

Usage and boring stuff

Just link it to any container listening on port 80 (let's call it LC for Linked Container):

docker run -d -p 80:80 -p 443:443 --link LC:www tecnativa/haproxy-letsencrypt

Then navigate to https://localhost and add security exception.

When the LC exposes other port

The proxy will use www:$PORT as origin, so run it as:

docker run -e PORT=8080 --link LC:www yajo/https-proxy

When you want custom error pages

This is preconfigured to use error pages from the examples. Just override the corresponding error page found in /usr/local/etc/haproxy/errors in your subimage:

FROM yajo/https-proxy
MAINTAINER [email protected]
ADD 400.http 503.http /usr/local/etc/haproxy/errors/

Automatic redirection of HTTP

This image will redirect all HTTP traffic to HTTPS, but this is a job that should be handled by your LC in production to avoid this little overhead.

To help your LC know it is proxied (because it will seem to the LC like requests come in HTTP form), all requests will have common additional headers like X-Forwarded-Proto: https and other common ones.

You can use that to make HTTPS (https://example.com/other-page) redirections, or just use relative (../other-page) or protocol-agnostic (//example.com/other-page) redirections and it will always work anywhere (this is a good practice, BTW).

If you don't want this forced redirection (to maintain both HTTP and HTTPS versions of your site), just expose port 80 from your LC and port 443 from the proxy.

Automatic redirection of www.example.com to example.com

This container reduces redundancy by removing the www. prefix to any request.

You can do it the other way around with -e WWW_PREFIX=FORCE, or disable it with -e WWW_PREFIX=0.

Special modes

You can use the MODE environment variable to switch to some special modes by setting it to any of these values:

NORMAL (default)

It simply adds its magic to redirect all HTTP(S) requests to the backend, as explained above.

ODOO

It redirects all requests for /longpolling and its subdirs to www:$ODOO_LONGPOLLING_PORT (www:8072 by default).

Normally you combine this mode with e PORT=8069, and you must configure correctly the workers parameter for the Odoo linked container. Check its docs for that.

Configuring Certbot

You can override the template in /usr/src/cli.ini with the default options that are going to be used. It gets environment variable-expanded in the entrypoint. Use any configuration you want.

By default you should use these environment variables to make it work:

STAGING

Set it to false to start using the real Let's Encrypt CA. By default (true) it uses the staging environment.

EMAIL

Set your real email to interact with Let's Encrypt.

DOMAINS

Comma-separated list of domains you are serving with this container (and for whom you want certificates).

Remember that if you are going to serve both www.example.com and example.com, you have to ask for both.

RSA_KEY_SIZE

By default it is a bit higher than Certbot's default: 4096.

Using replacement hooks

Some configuration files have hooks, such as # AFTER WWW HOOK. Those strings can be used as a replacement target in your subimage Dockerfile with sed -i to inject some extra rules in those places.

Feedback

Please send any feedback (issues, questions) to the issue tracker.

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.