Skip to main content

Create a hidden Service

Install Tor

To enable all package managers using the libapt-pkg library to access metadata and packages available in sources accessible over https (Hypertext Transfer Protocol Secure).

apt install apt-transport-https

Create a new file in /etc/apt/sources.list.d/ named tor.list. Add the following entries:

deb     [signed-by=/usr/share/keyrings/deb.torproject.org-keyring.gpg] https://deb.torproject.org/torproject.org trixie main
deb-src [signed-by=/usr/share/keyrings/deb.torproject.org-keyring.gpg] https://deb.torproject.org/torproject.org trixie main

Install GnuPG if not already installed:

apt install gnupg

Then add the gpg key used to sign the packages by running the following command at your command prompt:

wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --dearmor | tee /usr/share/keyrings/deb.torproject.org-keyring.gpg >/dev/null

Install tor and tor debian keyring

apt update
apt install tor deb.torproject.org-keyring

Configure Tor

Next, you need to configure Tor to host your hidden service. Open the Tor configuration file:

vim /etc/tor/torrc

Add the following lines at the end of the file:

HiddenServiceDir /var/lib/tor/hidden_service/
HiddenServicePort 80 127.0.0.1:80

Restart Tor

After making the changes, restart the Tor service to apply the configuration.

systemctl restart tor

Find Your Onion Address

The Tor service generates the onion address for your hidden service. To find it, check the hostname file.

cat /var/lib/tor/hidden_service/hostname

This command will output an onion address that you can use to access your site via the Tor network.

Install and Configure Nginx

If you haven't installed Nginx yet, you can do so with the following command:

apt install nginx

After installation, you need to configure Nginx to serve your website. Create a new configuration file for your onion service:

vim /etc/nginx/sites-available/onion

Add the following configuration:

server {
    listen 80;
    server_name your_onion_address.onion;

    location / {
        root /var/www/html;  # Change this to your website directory
        index index.html index.htm;
    }
}

Enable the Nginx Configuration

ln -s /etc/nginx/sites-available/onion /etc/nginx/sites-enabled/

Edit the Nginx Configuration

Open your main Nginx configuration file:

vim /etc/nginx/nginx.conf

Increase the Bucket Size

Add or modify the server_names_hash_bucket_size directive within the http block. You could set it to a larger value, like 128 or 256:

http {
    ...
    server_names_hash_bucket_size 128;
    ...
}

Test Nginx Configuration

Check for any syntax errors in the Nginx configuration:

nginx -t

Restart Nginx

If the configuration test is successful, restart Nginx:

systemctl restart nginx

Place Your Website Files

Place your HTML files in the designated directory (e.g., /var/www/html). You can create a simple index.html file to test:

echo "<h1>Welcome to My Onion Site!</h1>" | sudo tee /var/www/html/index.html