Deploy Strapi to AWS Lightsail in 10 minutes

With Strapi, we can use it for any Cloud Computing provider, and the best of them is AWS. Then, Lightsail is the easiest, cheapest and clearest to deploy Strapi in the very first stage of business.

The blueprint we will use in this article is quite simple and easy to approach.

  1. Instance (VPS) for running Strapi backend and admin dashboard
  2. Database (PostgreSQL) for running separately database
  3. Networking (Load Balancer) for running load balancing and SSL/TLS certificates
  4. Route53 for DNS configuration

Notice: we have to deploy all 3 first artifact in the same region for the best performance and cost

Assume you have an AWS account, so enter to Lightsail Console Management

Instance

Strapi cannot be built on VPS with less than 2GB RAM, so we will choose the closest option is 1vCPU and 2GB RAM.
Pricing is $10
We can choose the OS is created by Amazon. It’s a Redhat distro with some advantages like 5 years of update, reliable repository and very very light
The rest of configuration we will set by default and can be changed later

Database

We will choose Postgres with the minimum option: 1vCPU and 1GB RAM.
Pricing is $15.
Every configuration should be set by default.
After the DB instance is up and running. We should public the URL one time to setting up the new users for Strapi

Networking

Before install networking, please take some config with Strapi instance above to ensure the LB (Load Balancer) can check the status of the server
We have to install Nginx to be proxy reverse in the Instance and just leave 80 port open, because we will setup SSL on the LB

# Strapi server
upstream strapi {
    server 127.0.0.1:1337;
}

server {
    # Listen HTTP
    listen 80;

    # Proxy Config
    location / {
        proxy_pass http://strapi;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass_request_headers on;
    }
}

After the configuration is set, check the open port on the Strapi server by netstat -tupln
Attach the Strapi server into this LB and wait for the health check. If it pass, we can setup the Route53 with the CNAME point to endpoint of this LB

SSL Certification

In the Inboud traffic tab, create a new certificates with the domain name (ex: strapi.magestore.com) and we have to create the new DNS record followed by Lightsail instruction
After refresth the page, voila, we have SSL in our LB. The last step is assign it to the HTTPS list box

Good luck with your deployment!

anh chuyển mấy bài strapi của chú sang nhóm skill nhé