Skip to content

Instantly share code, notes, and snippets.

@gabeosx
Created December 10, 2022 20:59
Show Gist options
  • Save gabeosx/93b9b099dec830706bab3ee2513eba8a to your computer and use it in GitHub Desktop.
Save gabeosx/93b9b099dec830706bab3ee2513eba8a to your computer and use it in GitHub Desktop.
Obsidian LiveSync Self-Hosted on Synology

Intro

obsidian-livesync is an Obsidian plugin, which allows you to Synchronize your Obsidian vault between devices, using a CouchDB database.

Synology NAS devices offer Docker support, which is a convenient way to host your CouchDB.

Setup the CouchDB container on Synology

Pre-requisites

  1. Create a directory for your Docker data (e.g. /volume1/docker/obsidian-couchdb)
  2. Create a user with permissions to that directory - put them in the users group
  3. Get the UID and GID for the user. See: https://mariushosting.com/synology-find-uid-userid-and-gid-groupid-in-5-seconds/
  4. Upload your local.ini (example below)

Optional step

Although it is not required, I would highly recommend fronting your CouchDB with a reverse proxy and SSL.

mariushosting has a tutorial, so I will not create another one. https://mariushosting.com/how-to-install-nginx-proxy-manager-on-your-synology-nas/

Docker config in Synology task

The below docker command can be executed via a task, as mariushosting usually does.

  1. Open the Control Panel
  2. Open Task Scheduler from the Control Panel
  3. Click the "Create" button
  4. Choose Scheduled Task ➡️ User-defined script
    1. General tab
      1. Task: Install CouchDB
      2. User: root
    2. Schedule
      1. Run on the following date
        1. leave as today's date
        2. Do not repeat
      2. Time
        1. leave everything default
      3. Task settings
        1. Run command - put the command below in
      4. Click "Ok"
    3. If the task is checked, un-check it
    4. Highlight the task
    5. Click the "Run" button
docker run -d \
-e COUCHDB_USER=XXXXXXX \
-e COUCHDB_PASSWORD=XXXXXX \
-e PUID=XXXX \
-e PGID=XXX \
-v /volume1/docker/obsidian-couchdb/local.ini:/opt/couchdb/etc/local.ini \
-v /volume1/docker/obsidian-couchdb/data:/opt/couchdb/data \
-p 5984:5984 \
--restart always \
couchdb

local.ini

[couchdb]
single_node=true
max_document_size = 50000000

[chttpd]
require_valid_user = true
max_http_request_size = 4294967296

[chttpd_auth]
require_valid_user = true
authentication_redirect = /_utils/session.html

[httpd]
WWW-Authenticate = Basic realm="couchdb"
enable_cors = true

[cors]
origins = app://obsidian.md,capacitor://localhost,http://localhost
credentials = true
headers = accept, authorization, content-type, origin, referer
methods = GET, PUT, POST, HEAD, DELETE
max_age = 3600

Configure the LiveSync plugin

  1. Input the URL for your CouchDB
  2. Use the credentials you put into the Docker configuration
  3. Choose an arbitrary name for your database

References

obsidian-livesync documentation

https://github.com/vrtmrz/obsidian-livesync/blob/main/docs/setup_own_server.md

@philipp-koch
Copy link

This is really helpful! Thank you!

@justtiberio
Copy link

Does it also work with Obsidian on IOS? Can I use this to sync between my computers and my iPad?

@Katchyuser
Copy link

I tried to use this repo, but doesn't work for me.
I had to remove the two commands
-e PUID=XXXX
-e PGID=XXX
The couchdb is successfully installed on docker but does not work on Caddy hosted on another docker for https access
Can someone post detailed instructions about setting up caddy for https access?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment