How to Set Up a Hidden Service with Tor and Nginx

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.

Step 1: Install Tor

First, install Tor using the following command:

sudo apt update
sudo apt install -y tor

Step 2: Configure Tor for Hidden Service

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

Step 3: Restart Tor

Restart Tor to apply the configuration:

sudo systemctl restart tor

Step 4: Verify Tor is Running

Check that Tor is running properly:

sudo journalctl -e -u tor@default

Step 5: Install Nginx

Install Nginx to serve your website:

sudo apt install -y nginx

Step 6: Secure Nginx Configuration

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;
}

Step 7: Create Web Directory and Index.html

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>

Step 8: Test Nginx Configuration

Test your Nginx configuration for errors:

sudo nginx -t

Step 9: Restart Nginx

Restart Nginx to apply the configuration:

sudo systemctl restart nginx

Step 10: Get the .onion Address

Retrieve the .onion address from the Tor configuration:

sudo cat /var/lib/tor/hidden_service/hostname

Step 11: Final Message

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/