Keep in mind, that this is only a basic setup. Please refer to the Official TOR documentation.
Tested on Debian 12. Make sure you have Nginx installed and configured a Vhost on port 80, or change the config of this tutorial to whatever needed port.
Step 1: Install apt-transport-https and gpg.
# apt install apt-transport-https gpg -y
Step 2: Check what version of Debian you are running. For Debian 12, the version is called "bookworm".
# cat /etc/debian_version
Step 3: Create repository list file: "/etc/apt/sources.list.d/tor.list". Inside this file you will paste the following config:
deb [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org DISTRIBUTION main
deb-src [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org DISTRIBUTION main
Make sure to replace "DISTRIBUTION" with the name of your version. Again, for Debian 12 it is "bookworm".
Step 4: Add the GPG key of the TOR repository.
# wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --dearmor | tee /usr/share/keyrings/deb.torproject.org-keyring.gpg >/dev/null
Step 5: Update your package repositories and install tor and its keyring.
# apt update && apt install tor deb.torproject.org-keyring -y
Step 6: Configure TOR for hosting. Uncomment these two lines of config in your "/etc/tor/torrc" by removing the "#" in the beginning of the line.
#HiddenserviceDir /var/lib/tor/hidden_service
#HiddenServicePort 80 127.0.0.1:80
Step 7: Start TOR and enable the start of tor on boot.
# systemctl restart tor && systemctl enable tor
Your website is now hosted on the TOR network with an onion address. You can see your generated onion address with the following command:
# cat /var/lib/tor/hidden_service/hostname