This article walks you through setting up a hidden service using Debian, Tor and Nginx. A hidden service allows you to host a website with a .onion address, accessible only through the Tor network.
First, install Tor using the following command:
sudo apt update
sudo apt install -y tor
Configure Tor to create a hidden service and listen on port 8080.
This is what your /etc/tor/torrc might look like now:
HiddenServiceDir /var/lib/tor/hidden_service/
HiddenServicePort 80 127.0.0.1:8080
SocksPort 127.0.0.1:9050
ControlPort 0
DNSPort 0
Restart Tor to apply the configuration:
sudo systemctl restart tor
Check that Tor is running properly:
sudo journalctl -e -u tor@default
Install Nginx to serve your website:
sudo apt install -y nginx
Run sudo cat /var/lib/tor/hidden_service/hostname.
The result is your new onion address. You'll need it below.
Your /etc/nginx/sites-enabled/default file should look like:
server {
listen 127.0.0.1:8080;
server_name PASTE_YOUR_NEW_ONION_ADDRESS_HERE;
location / {
root /var/www/my_awesome_hidden_service;
index index.html;
autoindex off;
client_max_body_size 10M;
}
access_log /var/log/nginx/hidden_service_access.log;
error_log /var/log/nginx/hidden_service_error.log;
}
Create the directory and a simple HTML file for your website:
sudo mkdir -p /var/www/my_awesome_hidden_service
Copy this to /var/www/my_awesome_hidden_service/index.html
<html>
<head>
<title>Welcome to Zion</title>
</head>
<body>
<h1>Welcome to Zion.</h1>
</body>
</html>
Test your Nginx configuration for errors:
sudo nginx -t
Restart Nginx to apply the configuration:
sudo systemctl restart nginx
Retrieve the .onion address from the Tor configuration:
sudo cat /var/lib/tor/hidden_service/hostname
Your hidden service will be ready in a minute. You can access it using the Tor Browser.
You can view the HTML files for your site at:
/var/www/my_awesome_hidden_service/