Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 35 ยท Projects and Practice

Project: Deploy a Web App on a Droplet

A step-by-step project: create a Droplet, harden it, run an app with systemd behind Nginx, add HTTPS, monitoring and a backup, with checklist and config generators.

This project puts the chapter together. You will take a fresh Ubuntu Droplet to a small production setup: a non-root user, a firewall, an app that restarts by itself, Nginx as a reverse proxy, HTTPS, monitoring and a snapshot. The example app is a generic Node.js or Python web server listening on 127.0.0.1:8000; replace it with your own (the steps for a PHP or Ruby app differ only in the service command).

DigitalOcean is not available on this site, so every command is text for you to run on your own account, and nothing here shows invented output. The Python blocks are stand-ins that generate configuration and verify your checklist order.

The plan

flowchart LR
  V["Visitor"] -->|"HTTPS 443"| N["Nginx<br/>reverse proxy + TLS"]
  N -->|"127.0.0.1:8000"| A["App (systemd service)"]
  A --> D["Data: SQLite file or<br/>managed database"]
  CF["Cloud Firewall<br/>80, 443, SSH from your IP"] -.-> N

Only Nginx listens publicly; the app is bound to localhost.

Step 1: create and harden the Droplet

  1. Create an Ubuntu LTS Droplet in a region near your users, a small Basic size, with your SSH key, the monitoring option and a tag web. (CLI: doctl compute droplet create web-1 --region nyc1 --size s-1vcpu-1gb --image ubuntu-24-04-x64 --ssh-keys KEY_ID --enable-monitoring --tag-names web --wait.)
  2. Add a Cloud Firewall for tag web: 80 and 443 from anywhere, 22 from your own IP only.
  3. Log in as root once, create the deploy user, copy your key, disable root and password login, then enable ufw (all steps in SSH hardening). Better, put them in cloud-init so a new Droplet comes up like this every time.

Step 2: install and run the app

Terminal
sudo apt update && sudo apt install -y nginx git
sudo mkdir -p /srv/app && sudo chown deploy:deploy /srv/app
git clone https://example.com/you/app.git /srv/app
cd /srv/app && ./install-dependencies.sh      # your own build step

Run it with systemd, so it starts on boot and restarts after a crash:

INI
[Unit]
Description=My web app
After=network.target

[Service]
User=deploy
WorkingDirectory=/srv/app
EnvironmentFile=/etc/app.env
ExecStart=/srv/app/run-server --host 127.0.0.1 --port 8000
Restart=always
RestartSec=3
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

Save it as /etc/systemd/system/app.service, put secrets in /etc/app.env (mode 600, owner root), then:

Terminal
sudo systemctl daemon-reload
sudo systemctl enable --now app
systemctl status app
journalctl -u app -f
curl -s http://127.0.0.1:8000/healthz

Step 3: Nginx as a reverse proxy

The stand-in below generates the server block, so you can try different domains and ports.

Python Stand-in: generate an Nginx server block

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Save the output as /etc/nginx/sites-available/app, link it into sites-enabled, remove the default site, then sudo nginx -t && sudo systemctl reload nginx. Point the domain's A (and AAAA) record at the Droplet's IP, using DigitalOcean DNS (Networking, Domains) or your registrar.

Step 4: HTTPS

Terminal
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com --redirect
sudo certbot renew --dry-run

Details and pitfalls are in TLS certificates.

Step 5: monitoring and backups

  • Create CPU, memory and disk alert policies for tag web, and an uptime check for https://example.com/healthz.
  • Enable weekly backups, and take a snapshot named web-1-initial before you go live (see backups and snapshots).
  • Add a billing alert (cost control).

Order matters: a checklist verifier

Some steps depend on others: you cannot get a certificate before DNS points at the server, and you must allow SSH before enabling the firewall. This stand-in encodes those dependencies and checks a plan.

Python Stand-in: verify the deployment order

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Troubleshooting this setup

  • 502 Bad Gateway: Nginx cannot reach the app. Check systemctl status app, journalctl -u app, and that the port matches proxy_pass.
  • Site works by IP but not by name: DNS not propagated, or a wrong server_name.
  • Certbot fails: port 80 blocked by the firewall, or DNS points elsewhere.
  • App crashes on boot: missing environment file; EnvironmentFile path wrong.
  • Locked out of SSH: use the Droplet Recovery Console in the panel.

When you are done experimenting, delete the Droplet and the snapshot so they stop billing.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why bind the app to 127.0.0.1 instead of 0.0.0.0?

    A localhost bind keeps the app private; Nginx is the single public entrance.
  2. 2. What does Restart=always in the unit file do?

    systemd restarts the process so a crash does not leave the site down.
  3. 3. Which must be true before certbot can issue an HTTP-01 certificate?

    The CA connects to your domain over HTTP to verify control.
  4. 4. You get a 502 from Nginx. Where do you look first?

    502 means the upstream (your app) did not answer, so check systemd and journalctl.

Summary

  • A solid single-server setup: hardened Droplet, firewall, systemd service on localhost, Nginx proxy, Let's Encrypt, monitoring, backups.
  • Order matters: allow SSH before enabling ufw, point DNS before certbot.
  • Put repeatable parts in cloud-init or Terraform, and secrets in a protected environment file.
  • Tear down test resources when finished.

Next: Project: A Three-Tier Architecture