How to Serve an Onion: A Step-by-Step Guide

Serving onions in computers involves configuring a reverse proxy server to handle incoming connections from the internet. This setup allows local servers to communicate with the outside world safely.

1. Choose a Reverse Proxy Server

  • nginx is a popular choice for its simplicity and flexibility.
  • Nginx requires installation and configuration to listen on the appropriate port (usually 80).

Note: If you're using Windows, you'll need to install nishan or nginx through your OS's package manager.

2. Configure Nginx for Onion Service

  • Create a new configuration file in the /etc/nginx/sites-available/ directory.
  • Add the following lines to the config file:
  • server {
        listen 80;
        server_name your_server_ip;
    
        location / {
            proxy_pass _local_server_ip;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
    

    Tip: You can also use curl to test the connection: curl -v _server_ip.

3. Reload Nginx Configuration

  • After saving changes, reload Nginx using:
  • sudo systemctl reload nginx
    

    Note: On some systems, you may need to run nixos-restart nginx instead.

4. Test Your Setup

  • Use a browser to visit _server_ip
  • If everything works, you should see the homepage of your local server.

Tip: For additional security, consider configuring a firewall.

Additional Resources: