Lighttpd & Tor: vhosts

This guide presupposes that lighttpd and tor are installed and configured on your machine - as described in the lighttpd+tor howto.

In the steps below, the configuration files for Lighttpd and Tor will be edited for initializing a new onion virtual domain - to be run under the same instance of lighttpd. The new hostname can be automatically generated by Tor, or a custom hostname created by Shallot.

  1. lighttpd
  2. Tor
  3. Shallot

lighttpd

In a text-editor, open up ~/light/lighttpd.conf. Since a basic configuration exists for a single, hosted onion domain, add only the bolded entries, below, to the lighttpd.conf. Make substitutions for the usernames and hostnames - as needed. The directory for the web-content of the new domain will be located under /home/user/light/pages - the "server.document-root".

server.document-root = "/home/user/light/pages"
server.port = "8080"
server.bind = "127.0.0.1"
server.username = "user"
server.groupname = "www"
accesslog.filename = "/home/user/light/logs/access"
server.errorlog = "/home/user/light/logs/error"

$HTTP["host"] == "oldxxxxxxxxxxxxx.onion" {
simple-vhost.server-root = "/home/user/light/"
simple-vhost.default-host = "oldxxxxxxxxxxxxx.onion"
simple-vhost.document-root = "pages"
}

$HTTP["host"] == "newxxxxxxxxxxxxx.onion" {
server.document-root = "/home/user/light/pages/new/"
}


server.modules = (
"mod_simple_vhost",
"mod_redirect",
"mod_access",
"mod_setenv",
"mod_compress",
"mod_accesslog" )

mimetype.assign = (
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".txt" => "text/plain",
".png" => "image/png",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".mp3" => "audio/mpeg",
".ogg" => "application/ogg" )

static-file.exclude-extensions = ( "~", ".inc" )
index-file.names = ( "index.html", "index.htm" )


Test the configuration file for syntax errors. If necessary, fix them:

$ ~/light/sbin/lighttpd -t -f ~/light/lighttpd.conf

Create a directory for the new site's web-content.

$ mkdir ~/light/pages/new

Execute lighttpd

$ ~/light/sbin/lighttpd -f ~/light/lighttpd.conf

Place the web-content (html, images, audio and video files, etc.) to be served into ~/light/pages/new.

Tor

Create a new directory to hold the new onion hostname and its private key.

$ mkdir ~/tor/var/lib/tor/other_hidden_service

Open up ~/.torrc in a text editor. Copy and paste the following to it - but substitute your UNIX username for "user" - below.

HiddenServiceDir /home/user/tor/var/lib/tor/other_hidden_service/
HiddenServicePort 80 127.0.0.1:8080

If the new hostname was generated by shallot, copy and paste the output into "/home/user/tor/var/lib/tor/other_hidden_service/private_key".

Execute tor

$ ~/bin/tor

The new onion hostname is located in ~/tor/var/lib/tor/other_hidden_service as "hostname". Open the file "hostname":

$ cat ~/tor/var/lib/tor/other_hidden_service/hostname

To bring up the new site, copy and paste the onion hostname into the address bar of the Tor browser. The site is now available to users on the Tor network. It would be best to backup the private key and store it elsewhere (on a CD). In case of a disk crash - without any backup, a new key will be generated when Tor is run, and a different hostname assigned.

By adding more entries to lighthttpd.conf and .torrc for new hostnames - as above, the number of vhosts can be multiplied beyond the two illustrated above.

Custom hostnames

Onion hostnames generated by Tor are billed as: "opaque, non-mnemonic, 16-character alpha-semi-numeric hashes". They are just a random slaw of letters and numbers. However - with shallot, it's possible to create a semi-customized hostname, but only a part of the address (the first part) is user-selectable.

Download shallot, compile it then run it to create the first part of the hostname as "kheper".

$ wget https://github.com/katmagic/Shallot/archive/master.zip

$ unzip Shallot-master.zip

$ cd Shallot-master

$ ./configure

$ make

$ ./shallot ^kheper

Copy and paste the entire RSA key spit out from shallot to STDOUT into a new file named "private_key". Once "private_key" is copied into ~/tor/var/lib/tor/other_hidden_service and tor restarted, the hostname will appear in ~/tor/var/lib/tor/other_hidden_service/hostname.