Step 1: Launching an EC2 Instance
Go to EC2 and click on Launch Instance.
Add a name for your instance.
Select Ubuntu from Quick Start.
Choose the desired instance type.
For connecting to a Key pair, use a pre-existing key or create a new one.
In the Network setting, add a security group. A security group acts as a firewall, controlling both incoming and outgoing traffic from your instance.
Storage configuration is fine as gp2.
After this connect to your EC2 instance install node and create a mini project:
Installation guide:
https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04
Create a new project:
- npm init -y
- add a new file index.js
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
- npm i pm2 express
- pm2 start index.js
- pm2 save
Caddy
Step 1: Install Caddy
https://caddyserver.com/docs/install
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
sudo vim /etc/caddy/Caddyfile
:80 {
reverse_proxy localhost:3000
}
sudo systemctl restart caddy
Update the Caddyfile to use your domain name and enable HTTPS.
sudo vim /etc/caddy/Caddyfile
mydomain.com {
reverse_proxy localhost:3000
}
sudo systemctl restart caddy
Top comments (0)