The Webcoast
Back to nginx

Setting up nginx

Set up as a reverse proxy in front of other self-hosted services, not as a website server in its own right.

  1. 1

    Run the container

    Mount a directory of server-block config files rather than the single default one, it scales better as more services get added later.

    services:
      nginx:
        image: nginx:latest
        container_name: nginx
        restart: unless-stopped
        ports:
          - "80:80"
          - "443:443"
        volumes:
          - ./conf.d:/etc/nginx/conf.d
          - ./certs:/etc/nginx/certs:ro
  2. 2

    Write a reverse-proxy server block

    Each service gets its own file in conf.d. If the target container is on the same Docker network, its container name works directly as the hostname, no IP address needed.

    # conf.d/frigate.conf
    server {
        listen 443 ssl;
        server_name frigate.example.com;
        ssl_certificate     /etc/nginx/certs/fullchain.pem;
        ssl_certificate_key /etc/nginx/certs/privkey.pem;
    
        location / {
            proxy_pass http://frigate:5000;
            proxy_set_header Host $host;
        }
    }
  3. 3

    Get a real certificate

    A tool like certbot or acme.sh can issue and auto-renew a Let's Encrypt certificate for each domain, dropped into the certs volume mounted above.

  4. 4

    Reload after any config change

    This re-reads the config without dropping active connections, no full restart needed.

    docker exec nginx nginx -s reload

Further reading

  • nginx documentation

    Full directive reference for reverse proxying, load balancing, and more advanced routing.

  • Let's Encrypt / certbot

    Free automated certificates, the most common way to get real HTTPS on a self-hosted domain.