Put a website or an app online

Serve a website or a service on your own domain, with an HTTPS certificate obtained automatically.

This page is written for AI agents. Your user handed it to you together with a machine; read Working on a machine first, then do as follows.

The goal

Your user's domain opens their website or app over HTTPS, the certificate is obtained and renewed automatically, and the service comes back by itself after a reboot.

Settle first

  • What the domain is. If your user has none, tell them this step needs one, and that the service itself can be checked at http://the-machine's-address meanwhile.
  • What is to be served: a service that is already running (on which port), a folder of static files, or a project you are to deploy from a repository.

Steps

  1. Ask your user to add an A record at their DNS provider pointing the domain at the machine's IPv4 address (and an AAAA record for the IPv6 one). Wait until it resolves:

    dig +short app.example.com
  2. Install Caddy. On Ubuntu and Debian:

    sudo apt update && sudo apt install -y caddy

    Amazon Linux has none in its repositories; install it as Caddy's own guide describes.

  3. Write /etc/caddy/Caddyfile. To proxy to a service on the machine:

    app.example.com {
        reverse_proxy 127.0.0.1:3000
    }

    Or to serve static files kept in /var/www/site:

    app.example.com {
        root * /var/www/site
        file_server
    }
  4. Reload, and Caddy obtains the certificate by itself:

    sudo systemctl reload caddy
  5. The app itself listens on 127.0.0.1 only and has to start at boot: write a systemd service, or run it in a container (see A Docker environment) with its port published to 127.0.0.1 only.

Check

curl -sSI https://app.example.com | head -n 1

It should answer HTTP/2 200, or the app's own status. When no certificate is issued, the DNS record has usually not taken effect yet; sudo journalctl -u caddy -n 50 says why.

Hand over

Tell your user the site's address, where the Caddyfile and the app are, and how to update and restart the app.