Hidden services
Mastodon can be served through Tor as an onion service. This will give you a *.onion address that can only be used while connected to the Tor network.
Installing Tor
First Tor’s Debian archive needs to be added to apt.
Next add the gpg key.
Finally install the required packages.
Configure Tor
Edit the file at /etc/tor/torrc
and add the following configuration.
Restart tor.
Your tor hostname can now be found at /var/lib/tor/hidden_service/hostname
.
Move your Mastodon configuration
Create a new file at /etc/nginx/snippets/mastodon.conf
. Put all of your Mastodon configuration parameters in this file with the exception of the listen
, server_name
, include
and all of the SSL options. Your new file may look something like this.
In place of your old Mastodon configuration add an include directive to this new configuration file.
Your Nginx configuration file will be left looking something like this.
Serve Tor over http
The solution is to serve your Mastodon instance over http, but only for Tor. This can be added by pre-pending an additional configuration to your Nginx configuration.
Replace the long hash provided here with your Tor domain located in the file at /var/lib/tor/hidden_service/hostname
.
Note that the onion hostname has been prefixed with “mastodon.”. Your Tor address acts a wildcard domain. All subdomains will be routed through, and you can configure Nginx to respond to any subdomain you wish. If you do not wish to host any other services on your tor address you can omit the subdomain, or choose a different subdomain.
Here you can see the payoff of moving your mastodon configurations to a different file. Without this all of your configurations would have to be copied to both places. Any change to your configuration would have to be made both places.
Restart your web server.
Gotchas
There are a few things you will need to be aware of. Certain redirects will push your users to https. They will have to manually replace the URL with http to continue.
Various resources, such as images, will still be offered through your regular non-Tor domain. How much of a problem this is will depend greatly on your user’s level of caution.
Last updated
Was this helpful?