# Local Wikipedia

Broadly speaking, we want to:

1. Download a Wikipedia dataset
2. Host it in a local Docker container using Alpine Linux and kiwix-serve
3. Reverse-proxy to that container from an Nginx container (secure, lets you fudge TLS)
4. Use `mkcert` to create a fake Certificate Authority, trust that CA on your computer, and generate TLS certs for Nginx signed by the CA

# Downloading

Via the real https://en.wikipedia.org/wiki/Wikipedia:Database_download, we can find a download page with links like https://lbo.download.kiwix.org/zim/wikipedia/wikipedia_en_all_maxi_2026-02.zim.torrent (the current latest torrentable full Wikipedia dump at the time of this writing). In my case, I used [Torrra](https://github.com/stabldev/torrra) with [Jackett](https://github.com/Jackett/Jackett) - it's been a minute since I've dived too deep into the BitTorrent ecosystem, but now I understand that indexers like Jackett are an adapter layer, allowing trackers to use a wide variety of pseudo-standard comms formats, and torrent managers to outsource support for those formats.

The .zim file contains all of Wikipedia's content in one big archive. It doesn't contain HTML of sidebars and top navs and such, it's the raw database (think BBCode, if you're old enough to remember forums), so we need hosting software.

# Kiwix

Kiwix is an open-source suite of software tools for taking online knowledge to offline places. While the original goals were more about accessing knowledge in places like rural Africa, Kiwix is useful for anyone that wants to maintain a frozen copy of Wikipedia, or plenty of other datasets that are available.

This is accomplished with the "backend" container in `docker-compose.yml`. There really isn't too much to it: it's Alpine Linux with `kiwix-serve` installed (via the `kiwix-tools` package), and a command for running the service.

# Nginx

Nginx is probably the most popular reverse proxy software in the world. Having this buffer layer in place at all provides a bit of security for free. It also lets us do a couple things for better impersonating the real Wikipedia site. The first thing is just making `/wiki/...` URLs work, as internal rewrites before sending requests to the backend. The second is TLS support.

You can see the details in the `frontend.Dockerfile` and `nginx.conf` files. The configuration is minimally modified from the stock standard that comes with the `nginx:latest` container.

# mkcert

You'll want to make sure you have [mkcert](https://github.com/FiloSottile/mkcert) installed on your host machine, so you can create and install a fake CA, and then certs for en.wikipedia.org:

```bash
sudo pacman -Syu mkcert # Works on Arch, refer to docs for other platforms
mkcert -install
mkcert en.wikipedia.org
```

Now you can add this entry to your `/etc/hosts`:

```
# Local hosting of Wikipedia
127.0.1.1  en.wikipedia.org
```

Run both containers with `docker-compose up --build`. As long as your .zim and .pem files are in the top level of this repo, it should all just work, but you'll likely need to restart your browser(s) to see the results.