Edit the file at `/etc/tor/torrc` and add the following configuration.
```bash
HiddenServiceDir /var/lib/tor/mastodon/
HiddenServiceVersion 3
HiddenServicePort 80 127.0.0.1:80
```
Restart tor.
```bash
sudo service tor restart
```
Your tor hostname can now be found at `/var/lib/tor/mastodon/hostname`. This will work _if_ you are serving Mastodon over port 80 and _if_ it is the only site you are serving on your web server.
### Configuring a multi-host server
If you have multiple domains on your web server you will need to tell your web server how to serve the tor hostname. In the configuration file for your Mastodon web configuration add an additional hostname entry. e.g. for Nginx
While it may be tempting to serve your Tor version of Mastodon over https it is not good idea. See [this](https://blog.torproject.org/facebook-hidden-services-and-https-certs) blog post from the Tor Project about why https certificates do not add value. Since you cannot get an SSL cert for an onion domain, you will also be plagued with certificate errors when trying to use your Mastodon instance.
The solution is to serve your Mastodon instance over http, but only for Tor.
Consider the following example Nginx configuration.
```
server {
listen 80;
server_name mastodon.myhosting.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name mastodon.myhomsting.com;
…
}
```
Add a new server entry that duplicates the ssl entry, but defines it to use port 80 with your onion hostname.
You can also see [this Server Fault](https://serverfault.com/a/373661) answer for a more [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) solution.