# How to create a Tor hidden service website on Caddy on Debian 10

first published: 2020-01-31

last updated: 2021-01-13

1. Install Tor.

`sudo apt install tor`

2. Install the Caddy web server.

`echo "deb [trusted=yes] https://apt.fury.io/caddy/ /" | sudo tee -a /etc/apt/sources.list.d/caddy-fury.list`

`sudo apt update; sudo apt install caddy -y`

3. Edit `/etc/tor/torrc` to create the hidden service.

Open /etc/tor/torrc in your favorite text editor. (Please note that this usually requires root privileges.)

Go to the lines that say:

`#HiddenServiceDir /var/lib/tor/hidden_service/
#HiddenServicePort 80 127.0.0.1:80`

Uncomment them by deleting the # mark in front of each line.

If you want, you can change the HiddenServiceDir directory, but you will need to remember it for later. For security purposes, keep the new directory inside of `/var/lib/tor/`.

4. Restart the Tor service.

`sudo systemctl restart tor@default`

5. As root, go to the hidden service directory and get the new hidden service's domain.

`sudo -i`

`cd /var/lib/tor/directory/`

Replace "directory" with the actual directory you chose in step 3.

`cat hostname`

If all is well, you should now see a long string of letters and numbers that ends in ".onion". Copy this somewhere safe. You'll need it next step.

6. Configure Caddy to serve the hidden service.

Open `/etc/caddy/Caddyfile` with your favorite text editor. You should already be root, but if you did `exit` after getting the Tor hostname, just `sudo -i` again.

Type the following in:

    http://YourTorHostnameHere.onion {
    	root * /your/website/file/path/here
    	file_server
    	encode gzip
    	bind 127.0.0.1
    }

The "http://" in front of the address is important as that tells Caddy to not try to enable HTTPS on that domain. HTTPS is unnecessary for Tor hidden services as all traffic to and from the server is already encrypted in transit. And since Tor hidden services aren't accessible on the normal clearnet, the request for Let's Encrypt to give Caddy a certificate would fail as they wouldn't be able to access the domain.

8. Restart Caddy to apply your changes.

`sudo systemctl restart caddy`

CC BY-NC-SA 4.0 © Vane Vander