Commit 18b93c1c57

18b93c1c577aab687a99c844e356f3bc2a330647

parent: fea86f4282

Unsigned

cmc <hello@cleberg.net> · 2025-12-06 21:09 UTC

publish new post: self-hosting-tor

Layout: unified · split

content/blog/2025-12-06-self-hosting-tor.org added +115
@@ -0,0 +1,115 @@
1#+date: <2025-12-06 Sat 14:13:00>
2#+title: Self-Hosting Guide: Tor Websites
3#+description: Learn how to host your own website on Tor with an Onion Address in a few short steps!
4#+slug: self-hosting-tor
5
6* Installation
7
8First, install the Tor package. I'm using Ubuntu, so I'll be using =apt= to
9install Tor.
10
11#+begin_src sh
12sudo apt install tor
13#+end_src
14
15* Configuration
16
17** Tor
18Next, let's configure the service we'll be serving via Tor. For this, edit the
19file below and add the lines below to the end of the file.
20
21#+begin_src sh
22sudo nano /etc/tor/torrc
23#+end_src
24
25The following lines you add to the file will define the directory to use and the
26internet protocol (IP) address and port we will be using.
27
28#+begin_src text
29HiddenServiceDir /var/lib/tor/hidden_service/
30HiddenServicePort 80 127.0.0.1:5000
31#+end_src
32
33Next, you will need to =cat= the contents of the file below to find the onion
34address provided to you.
35
36#+begin_src sh
37sudo cat /var/lib/tor/hidden_service/hostname
38#+end_src
39
40** Nginx
41
42With this onion address handy, create a file in your Nginx configuration
43directory. Mine is =conf.d=, but yours may be =sites-available=. If that's the
44case, don't forget to create a symbolic link from the file you created in
45=sites-available= to =sites-enabled=.
46
47#+begin_src sh
48sudo nano /etc/nginx/conf.d/tor-website.conf
49#+end_src
50
51Within this Nginx configuration file, I will be using the file below. I have
52left comments to explain each part.
53
54#+begin_src conf
55server {
56 # The IP address and port Nginx will listen on
57 listen 127.0.0.1:80;
58 # The onion address to listen for
59 server_name sv3g2dlyvwyk2nvi3eeh55fcrpdvjlclhi6wwsx57cste6lwdjanzyyd.onion;
60 # The directory where your website files are
61 root /var/www/tor-website/;
62
63 # By default, try to serve the files. Return 404 if a file is not found.
64 location / {
65 try_files $uri $uri/ =404;
66 }
67
68 # Put any other configurations here at the end, such as redirects
69 # ...
70}
71#+end_src
72
73Finally, we can restart the services and check to see if it's working.
74
75#+begin_src sh
76sudo systemctl restart nginx.service
77sudo systemctl restart tor.service
78#+end_src
79
80At this point, you should be able to view your Onion address in Tor.
81
82[[https://img.cleberg.net/blog/20251206-self-hosting-tor/onion.webp]]
83#+caption: Onion Address in Tor
84
85** Onion-Location
86
87Lastly, let's advertise the =Onion-Location= on our clearnet website so that
88users on Tor can automatically switch to the Onion address if they want to.
89
90#+begin_src sh
91sudo nano /etc/nginx/conf.d/regular_website.conf
92#+end_src
93
94#+begin_src conf
95server {
96 server_name example.com;
97 add_header Onion-Location http://YourOnionAddress.onion$request_uri;
98}
99#+end_src
100
101Once complete, restart Nginx.
102
103#+begin_src sh
104sudo systemctl restart nginx.service
105#+end_src
106
107You should now see a big purple button in Tor titled =.onion available= when
108visiting the clearnet web page.
109
110[[https://img.cleberg.net/blog/20251206-self-hosting-tor/clearnet.webp]]
111#+caption: Onion-Location Button
112
113If everything worked, you're all done! You now have a website served via an
114onion address on Tor and an Onion-Location header advertising your new onion
115address.