1
0
Fork 0
mirror of https://git.fsfe.org/fsfe-system-hackers/reverse-proxy synced 2024-05-04 15:06:13 +02:00
Reverse proxy used to expose FSFE services
Go to file
max.mehl 501c72b179
download from dockerhub instead of build from github
2020-09-09 16:14:54 +02:00
errorpage Correct missing word on error.fsfe.org 2019-03-17 12:12:46 +01:00
rp Add default vhost config regardless of whether there are specific vhost settings 2020-06-10 19:24:14 +02:00
.drone.yml Specify the docker-compose project name (#5) 2019-04-18 20:32:20 +02:00
.gitignore Initial commit 2018-04-09 10:21:10 +02:00
LICENSE Initial commit 2018-04-09 10:21:10 +02:00
README.md Document the rp/extra-conf/ folder 2020-06-04 21:09:33 +02:00
docker-compose.yml download from dockerhub instead of build from github 2020-09-09 16:14:54 +02:00

fsfe-reverse proxy

This is the reverse proxy which exposes FSFE services and handles SSL termination (including Docker services).

How to use this?

To be included in the reverse proxy, a Docker container should be started with the environment variable VIRTUAL_HOST, for instance:

docker run -e "VIRTUAL_HOST=service.fsfe.org" ...

Let's Encrypt

To expose the service through HTTPS, use the following env variables when running you docker container:

LETSENCRYPT_HOST: <domain>
LETSENCRYPt_emaIL: <email>

Please make sure that resolves to the public IP address of the server where the reverse proxy is.

Per virtual host configuration

If you want to customize the nginx configuration for a virtual host, add or modify rp/extra-conf/domain.org.

External Services

Services which run externally to the Docker host can be included in the proxy by including a relevant configuration for them in the sites-enabled/ directory. Please note that any configuration files must match *.conf

How does it work?

The reverse proxy automatically adds SSL certificates (via LetsEncrypt) and sets up the reverse proxy for any Docker containers running locally.

It does that by monitoring container creation and deletion and updating its configuration accordingly. Here is an example of the generated configuration for our discourse installation:

upstream community.fsfe.org {
    server xxx.xxx.xxx.xxx;
}
server {
    server_name community.fsfe.org;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    return 301 https://$host$request_uri;
}
server {
    server_name community.fsfe.org;
    listen 443 ssl http2 ;
    include /etc/nginx/vhost.d/default;
    location / {
        proxy_pass http://community.fsfe.org;
    }
}

Building and deploying the reverse proxy

The reverse proxy itself is composed of three docker containers.

rp

In the rp folder, there is the Dockerfile used to build the nginx-based reverse proxy. It is build on top of that image.

There are three modifications:

  • it includes the site-enabled folder in the nginx configuration, so it's easy to use this reverse proxy with non-dockerised services.

  • The rp/nginx.tmpl file (original version here) has been modified to use a redirect instead of a 503 HTTP error in case nginx can't find the requested virtual host.

  • The rp/nginx.tmpl file (original version here) has been modified to use a redirect if a container is down (and has the VIRTUAL_HOST environment variable).

rple

The rple container is the let's encrypt companion. It is responsible for issuing and managing the TLS certificates used by the reverse proxy. More info in the official repository.

rp-errorpage

The errorpage folder contains a simple container that displays an error page if the reverse proxy can't find the requested VIRTUAL_HOST.

Deployment with the ansible playbook

The ansible playbook builds the two docker images mentioned above, and run the containers with the right parameters. Here is a list of the non-self-explanatory ones:

  • The labels com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy is needed by the rple container so it knows for which nginx container it should manage certificates.
  • volumnes_from tell docker to use the same volumes for both containers. We still need to specify the volumes instruction for both containers because they don't have the same rights over the volumes.