GithubHelp home page GithubHelp logo

doodaz / docker-nginx-letsencrypt-https-ec2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from karthickcse05/docker-nginx-letsencrypt-https-ec2

0.0 0.0 0.0 2 KB

Setup https with nginx on docker + certbot in aws ec2

Dockerfile 100.00%

docker-nginx-letsencrypt-https-ec2's Introduction

HTTPS setup: Nginx Reverse Proxy+ Letsencrypt+ AWS Cloud EC2 + Docker

Below is a basic setup guide:

Step-1: Open config/nginx.conf replace test.karthickcse05demo.xyz with the domain you wish to configure. It can be subdomain like mine or apex domain.

Step-2: You can change the nginx version in docker/nginx.Dockerfile

Step-3: Open docker-compose-cert.yaml and replace [email protected] and test.karthickcse05demo.xyz

Step-4: In a terminal (T1) run docker-compose up --build nginx monitor the logs for errors as we follow next steps

Step-5: In another terminal (T2) run docker-compose -f docker-compose-cert.yaml up --build

Step-6: If things go well, the second terminal (T2) will show something like this

letsencrypt_1  | Certificate is saved at: /etc/letsencrypt/live/yourdomain.com/fullchain.pem
letsencrypt_1  | Key is saved at:         /etc/letsencrypt/live/yourdomain.com/privkey.pem
letsencrypt_1  | This certificate expires on 2021-10-20.
letsencrypt_1  | These files will be updated when the certificate renews.
letsencrypt_1  |
letsencrypt_1  | NEXT STEPS:
letsencrypt_1  | - The certificate will need to be renewed before it expires. Certbot can automatically renew the certificate in the background, but you may need to take steps to enable that functionality. See https://certbot.org/renewal-setup for instructions.
letsencrypt_1  |
letsencrypt_1  | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
letsencrypt_1  | If you like Certbot, please consider supporting our work by:
letsencrypt_1  |  * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
letsencrypt_1  |  * Donating to EFF:                    https://eff.org/donate-le
letsencrypt_1  | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Step-7: Close the nginx container (press Ctrl+c or CMD+c) running in first terminal (T1) and replace with below config (after replacing the 4 occurence of test.karthickcse05demo.xyz with your domain name)

server {
    listen 80;
    listen [::]:80;
    server_name test.karthickcse05demo.xyz;
location / {
        rewrite ^ https://$host$request_uri? permanent;
    }
location ~ /.well-known/acme-challenge {
        allow all;
        root /tmp/acme_challenge;
    }
}
server {
    listen 443 ssl;
    listen [::]:443 ssl http2;
    server_name test.karthickcse05demo.xyz;
ssl_certificate /etc/letsencrypt/live/test.karthickcse05demo.xyz/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/test.karthickcse05demo.xyz/privkey.pem;
}

Step-8: Run the nginx container again but with -d this time docker-compose up --build -d nginx SSL certificates should be installed. Verify by visiting your domain. You will get an Nginx 404 but it will be served over https. Check the certificate details.

Step-9: Setup crontab for auto-renew by running command crontab -e and then pasting the below stuff there. Make sure you put the absolute path to the docker-compose file. 0 0 * * 0 expr `date +\%W` \% 2 > /dev/null || docker-compose -f <absolute path to folder>/docker-compose-cert.yaml up && docker exec -it nginx-service nginx -s reload

The cron job should do two things:

  1. Run the letsencrypt certbot container. docker-compose -f /docker-compose-cert.yaml up
  2. Tell nginx server to reload newly installed certificates docker exec -it nginx-service nginx -s reload

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.