DEV Community

Cover image for Proxy requests to an onion service using TorProxy and Caddy
Erfan Besharat
Erfan Besharat

Posted on

Proxy requests to an onion service using TorProxy and Caddy

Sometimes you may want to proxy a subdomain of your website or a local URI on your machine to a page on the onion network. Using Caddy with TorProxy plugin enabled, you can proxy more than one URI to a onion service.

Installation

You can install Caddy+Torproxy by downloading the binary directly from the Caddy Build Server or use the one-step installer script.
Note that you have to install the tor daemon itself on your machine too since torproxy needs that to operate correctly.

Installer Script

Run the following command to install Caddy with torproxy plugin enabled. Just note that the license used in the command is "personal". Either change the command manually or generate another one-step installer from the Build Server.

$ curl https://getcaddy.com | bash -s personal http.torproxy

Configuration

For using Caddy you need to write a Caddyfile and configure the URIs and the endpoints for TorProxy inside that file.

Optional: Local-Environment Setup

If you just want to test TorProxy on your machine, you have to add an custom hostname to the /etc/hosts file on your machine and point it to 127.0.0.1.
Example /etc/hosts:

127.0.0.1   mysecretsite.test

Caddyfile

Point the URIs to your endpoint onion services like this example:

mysecretsite.test {
  torproxy mysecretsite.test somewhereonthe.onion 
}

After writing the configuration, run this command and pass your Caddyfile as a value for -conf flag:

$ torproxy -conf ./Caddyfile

Extra: Development Build

If you're curious and want to play with the code, you can follow these steps to generate a development build of TorProxy with Caddy included.
Run the following command to get torproxy's source code and switch your working directory to the torproxy repository

$ git clone git.okkur.org/torproxy && cd torproxy

Then run the following command to download the dependencies to your local cache

$ go mod download

And then run go install or go build to compile the source code.

Do not forget to install Tor itself on your machine since torproxy needs that to operate correctly.

Please write an issue on TorProxy's GitHub repository if you faced any issues or bugs or just have a feature request :)

Top comments (0)