2024-12-12

Hosting a tootik server and a gemini capsule on the same machine, with nginx

Recently spun up an instance of tootik, the ActivityPub server software that speaks the gemini protocol, on my Debian server.

tootik on GitHub

The official setup guide is great - however, as a bit of a noob still, it took me a bit of trial and error to get it working alongside the existing gemini capsule on my machine, so I figured I'd write up a quick guide for anyone else that wants to do something similar. This should work for any gemini server that allows you to choose the port it listens on. I'm currently using gmCapsule.

* * *

Steps to get everything working, assuming you've already installed a gemini server that hosts your capsule and want to add tootik:

Basic stuff: DNS & nginx

complete steps 1 & 2 from the tootik setup guide:

https://github.com/dimkr/tootik/blob/main/SETUP.md

Install nginx and certbot; you will probably also want the python3-certbot-nginx plugin.

In a terminal, go to /etc/nginx/sites-available and then run

to create a super basic nginx config containing the following:

Save this, then create a soft-link to this file by running:

check the nginx config:

if everything is OK, then restart nginx and run certbot on your tootik domain:

Forwarding the request headers

open up /etc/nginx/sites-available/tootik again. You should now have two separate server blocks, one listening port 80 (http) that now redirects to the other server block listening on port 443 (https).

Add the following *inside the port 443 server block*, replacing port 8080 with whatever internal port you want tootik to listen on for http. These lines ensure that the request headers are forwarded to the tootik instance, as described in the 'Running behind a reverse proxy' section of the setup guide:

Is some of this redundant? Maybe, I genuinely don't know. But it works :))

Next, complete steps 5 to 7 of the tootik setup guide. For step 8, make sure to refer once again to 'Running behind a reverse proxy' for instructions on running tootik from the command line. Then perform step 9.

Don't cross the gemini streams

This was the other part that had me scratching my head while setting things up. Nginx doesn't recognize gemini:// addresses, so it wasn't clear how I could get nginx to listen for all gemini traffic on external port 1965, and then reverse proxy traffic to both my gemini capsule, and the tootik server. Luckily, someone had provided a clue:

https://pastebin.com/QHWhAWyM

My understanding is that a 'stream' block added to /etc/nginx.conf allows arbitrary data (i.e., anything not using a protocol recognized by nginx e.g. http) to be proxied.

Anyway, working on the same logic as the pastebin example, I added the following lines to /etc/nginx.conf, right after the end of the http block.

once again check that your nginx config is OK, and if so, restart it:

And continue to step 10 of the setup guide.

Lastly, here's what the first part of the tootik start command will look like, assuming you're using the ports in the example code above:

... etc

* * *

If this post helped you, feel free to send me a message from your working tootik instance: patatas@tootik.patatas.ca

(home)