# Free TLS with  Caddy Web Server on AWS EC2 with Let's Encrypt

## Overview

<figure><img src="https://2684022488-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOFDKnFMEMmJjoclGx9Hr%2Fuploads%2FlqviuRLHgh8BLu5boz26%2Fimage.png?alt=media&#x26;token=d9dda3d1-2c75-4160-9878-2502c9d74399" alt=""><figcaption></figcaption></figure>

In this tutorial we will see how to deploy a static website on AWS EC2 using Caddy web server with automatic HTTPS certificates from Let's Encrypt.                                                                                                                                                                                                             &#x20;

&#x20;What you'll build:                                                                                                        &#x20;

&#x20;• Complete AWS infrastructure (VPC, subnet, security groups, EC2 instance)

&#x20;• DNS configuration via Route 53

&#x20;• Caddy web server with automatic HTTPS

&#x20;• Static website accessible via custom subdomain

&#x20;• Production ready setup with HTTP to HTTPS redirect

all in less than 10 min

## How Stakpak Helps?

You don't need to know anything about networking, or AWS or Caddy to sit it up, you dont need to go through documentation or Google commands

## Step by Step Guide

### Prerequisites

1. [install-stakpak](https://stakpak.gitbook.io/docs/get-started/install-stakpak "mention")
2. Open your terminal and type "stakpak"
3. Cloud provider credentials configured

### Turorial

1. Then ask Stakpak to "install caddy on Ubuntu on EC2 "
2. It will start by checking the AWS creds and region

<figure><img src="https://2684022488-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOFDKnFMEMmJjoclGx9Hr%2Fuploads%2FhN13ajiZkQtsvzErnL7A%2Fimage.png?alt=media&#x26;token=18f39332-6df1-4701-8b21-831440ad8aaf" alt=""><figcaption></figcaption></figure>

6. it will create&#x20;
   1. Internet Gateway
   2. &#x20;Attach Internet Gateway to VPC
   3. &#x20;Create a public subnet
   4. Create a route table with an internet route
   5. Create security group (ports 22, 80, 443)
   6. Generate SSH key pair
7. Now it will create the EC2 instance&#x20;
8. Now we drink coffee while the EC2 instance starts
9. Now it will set the DNS and install Caddy, and test it

   <figure><img src="https://2684022488-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOFDKnFMEMmJjoclGx9Hr%2Fuploads%2FzMyktY8V2dHvtLJUAohy%2Fimage.png?alt=media&#x26;token=079bfd7d-b74b-44a6-ad78-2f710c51d0df" alt=""><figcaption></figcaption></figure>

## Now it's working🥳

<figure><img src="https://2684022488-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOFDKnFMEMmJjoclGx9Hr%2Fuploads%2FOHdlxC8CgdyJM7mwN5zu%2Fimage.png?alt=media&#x26;token=40178426-4c41-4abf-a873-4a1680dda068" alt=""><figcaption></figcaption></figure>

## Extra Resources:

### References

* [install-stakpak](https://stakpak.gitbook.io/docs/get-started/install-stakpak "mention")
* [EC2 Documentation](https://docs.aws.amazon.com/ec2/)
* [VPC Documentation](https://app.gitbook.com/u/dQf4Y4fhl0SFZ7GYMlOqGVTlVOg2)
* [Route 53 Documentation](https://docs.aws.amazon.com/route53/)
* [Caddy Documentation](https://caddyserver.com/docs/)
