Home · Guides / 4

Guide 4 of 5

How to create a .onion web server

Tor is now forwarding port 80 to 127.0.0.1:80. NGINX should listen only on localhost so the site is reached through the onion address, not as a public clearnet vhost.

Install NGINX

  1. Install NGINX from APT.

    sudo apt install nginx
    apt install nginx completing on Ubuntu
    NGINX installed from the Ubuntu repository.
  2. Edit the default site so it is linked to Tor’s localhost listener.

    sudo vi /etc/nginx/sites-enabled/default
  3. Change listen so it binds to 127.0.0.1, and set server_name to your onion address.

    server {
        listen 127.0.0.1:80 default_server;
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;
        server_name websitehz44l75xucojrrqofi4v7rn4y75wu6ocn7zbwjazgr44prfyd.onion;
    
        location / {
            try_files $uri $uri/ =404;
        }
    }
    Replace the server name Use the hostname from /var/lib/tor/hidden_service/hostname. Comment out any listen 80 default_server; line that binds on all interfaces.
    NGINX default site with listen 127.0.0.1:80 and an onion server_name
    Default site edited to listen on localhost and use the onion name.
  4. Restart NGINX.

    sudo service nginx restart

Publish a test page

  1. Go to /var/www/html and remove the default files.

    Empty /var/www/html after deleting the default index files
    Document root cleared of the packaged index page.
  2. Create a simple test file.

    vi index.html

    Type some text, then save.

  3. Open the site in Tor Browser and confirm it loads. Your address will differ from the example.

    Tor Browser displaying a test page at a .onion address
    The test page served over the onion address.

Need a dynamic stack? Continue with PHP and MySQL.