Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certbot LetsEncrypt support for generating certificates #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ clean-conf:
clean-data:
@bash generate_conf.sh delete_data

clean: clean-docker clean-conf
clean: clean-docker clean-conf

gen-https-cert: install https
@bash generate_conf.sh gen_https_cert
4 changes: 4 additions & 0 deletions data/nginx/http.conf.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ server {
listen 80;
client_max_body_size 100m;

location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

# Proxy requests to the bucket "outline" to MinIO server running on port 9000
location /outline-bucket {
include /etc/nginx/conf.d/include/proxy.conf;
Expand Down
4 changes: 4 additions & 0 deletions data/nginx/https.conf.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ server {

client_max_body_size 100m;

location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

# Proxy requests to the bucket "outline" to MinIO server running on port 9000
location /outline-bucket {
include /etc/nginx/conf.d/include/proxy.conf;
Expand Down
60 changes: 60 additions & 0 deletions data/nginx/https_certbot.conf.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# modified from https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-nginx-on-centos-7#step-3-configure-nginx-to-use-ssl
server {
listen 443 http2 ssl;
listen [::]:443 http2 ssl;

ssl_certificate /etc/letsencrypt/live/main_cert/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/main_cert/privkey.pem;
ssl_dhparam /etc/ssl/certs/dhparam.pem;

########################################################################
# from https://cipherli.st/ #
# and https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html #
########################################################################

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
# Disable preloading HSTS for now. You can use the commented out header line that includes
# the "preload" directive if you understand the implications.
#add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;

##################################
# END https://cipherli.st/ BLOCK #
##################################

client_max_body_size 100m;

location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

# Proxy requests to the bucket "outline" to MinIO server running on port 9000
location /outline-bucket {
include /etc/nginx/conf.d/include/proxy.conf;
# minio has its own tls implementation
proxy_pass https://minio:9000;
}

# Proxy any other request to the application server running on port 9001
location / {
include /etc/nginx/conf.d/include/proxy.conf;
proxy_pass http://outline:3000;
}
}


server {
listen 80;
return 301 https://$host$request_uri;
}
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ services:
volumes:
- ./data/nginx/:/etc/nginx/conf.d/:z
- ./data/certs/:/etc/ssl/certs/:z
- ./data/certbot/conf:/etc/letsencrypt:z
- ./data/certbot/www:/var/www/certbot:z
restart: always
depends_on:
- outline
- certbot
certbot:
image: certbot/certbot
restart: unless-stopped
volumes:
- ./data/certbot/conf:/etc/letsencrypt:z
- ./data/certbot/www:/var/www/certbot:z
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
14 changes: 14 additions & 0 deletions generate_conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,18 @@ function init_data_dirs {
mkdir -p data/minio_root/${AWS_S3_UPLOAD_BUCKET_NAME} data/pgdata
}

function gen_https_cert {
# get url from outline env
set -o allexport; source env.outline; set +o allexport
docker-compose run --rm --entrypoint "certbot certonly --webroot -w /var/www/certbot --agree-tos --force-renewal --cert-name main_cert -d ${HOST}" certbot
pushd data/nginx
rm -f default.conf
ln -s https_certbot.conf.disabled default.conf
popd
# rm data/certs/public.crt
# rm data/certs/private.key
# ln -s data/certbot/conf/live/main_cert/fullchain.pem data/certs/public.crt
# ln -s data/certbot/conf/live/main_cert/privkey.pem data/certs/private.key
}

$*