Setting Up TiddlyWiki on a Remote Server with Systemd & Nginx
TiddlyWiki is a cool tool, but if you, like me, are insane interested in getting it set up on the cloud, it can be a bit of a hassle. Here's a quick set of instructions to get it to run automatically as a service on a Linux server - I used a Hetzner Ubuntu machine.
Install TiddlyWiki and create a server:
npm install -g tiddlywiki
tiddlywiki {server name} --init server
Create a systemctl file for Tiddlywiki, e.g. etc/systemd/system/tiddlywiki.service
Add the following for a barebones systemd service:
[Unit]
Description=TiddlyWiki Server
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User={your user}
WorkingDirectory=/home/{your user}
ExecStart=tiddlywiki {your server} --listen
[Install]
WantedBy=multi-user.target
Run sudo systemctl start tiddlywiki
to run the service with systemd, and sudo systemctl enable tiddlywiki
to tell systemd to automatically run it on startup. If you're on a local machine, it should open at http://localhost:8080
.
If you're on a cloud server like I was, you'll need to set up Nginx to route to your server. To add a route to your TiddlyWiki, in this example /notes
, open up /etc/nginx/sites-available/{your-site}
and add the following. Make sure you add the trailing slashes to both the location and the proxy pass URLs. Nginx may mess up your routing due to default settings otherwise - explanation here.
location /notes/ {
proxy_pass http://127.0.0.1:8080/;
}
Run sudo systemctl restart nginx
and you should be able to see it in the browser!
But, you'll probably run into some issues with saving: you'll need to navigate into the folder where your tiddlywiki is located and tell tiddlywiki to redirect requests to the correct path. Once you're in that folder, cd into the tiddlers folder:
cd tiddlers
And create a file called '$__config_tiddlyweb_host.tid'
- note the quotation marks around the filename. At least on my server, it won't detect this tiddler unless you add the quotation marks.
Open that file, and add the following, making sure you update it to reflect the routes used in your Nginx .conf
file:
title: $:/config/tiddlyweb/host
$protocol$//$host$/${route_you_used_for_nginx}/
Run sudo systemctl restart tiddlywiki
to restart the service, and you should be in business!
References:
Installing TiddlyWiki on NodeJS
Nginx Reverse Proxy on ServerFault
Creating a Linux service with systemd