Tor Server Setup
Install tor and stop it's auto started service.
sudo apt install tor && sudo service tor stopThen edit it's config file /etc/tor/torcc
SocksPort 0
SocksListerAddress 127.0.0.1
 
RunAsDaemon 1
DataDirectory /var/lib/tor
 
HiddenServiceDir /var/lib/tor/my_onion_service
HiddenServicePort 80 127.0.0.1:8921After configurations start tor.
service tor startInfo
The above automatically creates a hostname (onion url) with it's public and private key pair in the directory specified with the option HiddenServiceDir inside torcc.
Next create an nginx config for the site with the ServerName option set to the generated hostname
Source [1] (opens in a new tab) [2] (opens in a new tab) [3] (opens in a new tab)
Troubleshooting
Nginx bucket size needs to be increased. The length of a tor address overshoots default config limitations