Project: Deploy an App on a Linux Server
Let's put the course together and plan a real deployment: your API in Docker on an Ubuntu server, behind Nginx, with HTTPS.
Deploying means taking your app from your laptop to a server where anyone can use it. This project follows a real, common setup: a Linux server, Docker for the app, Nginx in front, and free HTTPS. Each step uses skills from earlier lessons.
1. Prepare the server
Example
ssh ubuntu@203.0.113.10
sudo apt update && sudo apt upgrade -y
sudo adduser --disabled-password shop # a separate user for the app
sudo ufw allow OpenSSH && sudo ufw allow 'Nginx Full' && sudo ufw enable
# install Docker Engine using the steps on docs.docker.com for Ubuntu
sudo apt install -y nginx2. Get the code and start it
Example
git clone https://github.com/you/shop-api.git
cd shop-api
nano .env # add DB_PASSWORD and other secrets here (never in Git)
chmod 600 .env
docker compose up -d --build
curl http://localhost:3000/health3. Nginx in front
Nginx receives web traffic on ports 80/443 and passes it to your app. It also serves static files fast and handles HTTPS.
Example
# /etc/nginx/sites-available/shop
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Example
sudo ln -s /etc/nginx/sites-available/shop /etc/nginx/sites-enabled/
sudo nginx -t # check the settings for mistakes
sudo systemctl reload nginx4. Free HTTPS
Example
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d api.example.com # gets a Let's Encrypt certificate and renews it automatically5. Keep it healthy
- Check logs:
docker compose logs -fand/var/log/nginx/error.log - Back up the database every day (
pg_dumpto a file, copied off the server) - Watch disk space with
df -h - Update the server regularly; update the app with
git pull && docker compose up -d --build - Later: automate deploys with GitHub Actions
Point your domain's DNS A record at the server's IP address before running certbot.
api.example.com and 203.0.113.10 are placeholder examples.Key points
- Prepare the server: updates, a user, a firewall.
- Run the app with Docker Compose.
- Nginx in front plus certbot for HTTPS.
📝 Test yourself
1. What does Nginx do in this setup?
2. Which command checks the Nginx settings before reloading?
3. Fill in the tool that gets free HTTPS certificates:
sudo --nginx -d api.example.com
