# My home site

A front page with your photos, a short "currently" list and a list of your self-hosted services, plus a login that protects the services themselves.

- **Caddy** serves the front page and handles HTTPS certificates automatically.
- **Authelia** is the login portal (password + authenticator app) at `auth.<your domain>`.
- Each protected service gets its own subdomain, and Caddy sends anyone who isn't signed in to the login first.

```
you ──► Caddy ──► example.com          front page (public)
             ├──► auth.example.com     login portal (Authelia)
             └──► media.example.com    your service, only after login
```

## What you need

- A server with Docker and Docker Compose.
- A domain name, with DNS records for `example.com` and `*.example.com` pointing at your server's public IP.
- Ports 80 and 443 forwarded from your router to the server.

## Set it up

```bash
./setup.sh
docker compose up -d
```

`setup.sh` asks for your domain, a username, your email and a password. It creates `.env` with random secrets and writes your login to `authelia/users_database.yml`.

Then:

1. Open `https://auth.<your domain>` and sign in.
2. Authelia asks you to register an authenticator app. Because no email server is set up, the verification code is saved in `authelia/notification.txt`. Open that file on the server, copy the code or link, and finish registering.
3. Open `https://whoami.<your domain>`. You should see a page of request details. That proves the login protects a service. Delete the `whoami` blocks from `docker-compose.yml` and `Caddyfile` when you're done testing.

## Make the front page yours

All the content is in `site/data/`:

| File | What it controls |
| --- | --- |
| `site.json` | Your name, headline, intro, the "Currently" list, footer, server time zone |
| `photos.json` | The gallery: file name, title, caption, alt text, size |
| `services.json` | The services list |

**Photos.** Put resized copies (about 1600 px on the long edge) in `site/photos/`, delete the `sample-*.jpg` files, then run:

```bash
pip install pillow
python3 tools/make_photos_json.py
```

This adds new files to `photos.json` and removes entries for deleted files. Open the JSON afterwards to write titles and captions. Photos are shown in the order of that file.

Strip location data (EXIF) from photos before you publish them if you don't want your whereabouts public. `exiftool -all= photo.jpg` does it.

**Services.** Each entry in `services.json` has a `name`, a `description` and either `sub` (the subdomain, so `"sub": "media"` links to `media.<your domain>`) or a full `url`. Services show a lock and "Sign in required" unless you add `"public": true`.

Changes to the files in `site/` show up on refresh. No rebuild or restart.

## Add a protected service

1. Add a block to the `Caddyfile`, copying the commented example. The service must be reachable from the Caddy container: either on the same Docker network (use its container name) or published on a host port (use `host.docker.internal:<port>`).
2. Reload: `docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile`
3. Add it to `site/data/services.json`.

**Apps with their own login or mobile apps.** Jellyfin, Immich, Vaultwarden and Nextcloud have phone and desktop apps that can't get past the Authelia login page. For these, skip the `forward_auth` block and use the service's own login (with a strong password and two-factor turned on in the service). The `Caddyfile` has an example.

## Good to know

- **Access policy.** `authelia/configuration.yml` requires a password and an authenticator code (`two_factor`) for every subdomain. Change it to `one_factor` for password only.
- **Add another user.** Generate a hash with `docker run --rm authelia/authelia:4.39 authelia crypto hash generate argon2 --password 'their-password'`, add a new entry in `authelia/users_database.yml`, then `docker compose restart authelia`.
- **Lost authenticator.** Delete `authelia/db.sqlite3` and restart Authelia to re-enroll everyone. It also clears sessions.
- **Backups.** Keep `.env`, `authelia/` and `site/`. The `caddy_data` Docker volume holds your certificates, but they re-issue on their own.
- **Fonts.** The page uses your system's fonts so nothing loads from a third party. To use your own, drop `.woff2` files in `site/` and add `@font-face` rules to `style.css`.
- **Only on your home network?** Certificates from the default method need the server reachable from the internet. For a private setup, use Caddy's DNS challenge with your DNS provider instead (see the Caddy docs on `tls` with `dns`).
- **Without a domain yet.** Opening `site/index.html` through any local web server (for example `python3 -m http.server` inside `site/`) shows the page, but the sign-in button stays hidden until the page is served from a real domain. Set `signInUrl` in `site.json` to override.
