Joplin vieweb setup - gri38/django-joplin_vieweb Wiki

Original URL: https://github.com/gri38/django-joplin_vieweb/wiki/Joplin-vieweb-setup

This page will explain how to install joplin-vieweb with daphne and gninx and Let's encrypt for TLS.

Django stuff

mkdir ~/.joplin-vieweb
cd ~/.joplin-vieweb
python3 -m venv venv
. venv/bin/activate
pip install --upgrade pip
pip install django-joplin-vieweb
pip install daphne
pip install Twisted[tls,http2]
django-admin startproject joplinweb
cd joplinweb

Edit joplinweb/settings.py and add or modify:

DEBUG = False

ALLOWED_HOSTS = ['my.domain.com']

INSTALLED_APPS = [
    'joplin_vieweb',
   ...
]

STATIC_URL = '/static/'
import os
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

# Joplin variables
JOPLIN_SERVER_URL="http://127.0.0.1"
JOPLIN_SERVER_PORT=41184
JOPLIN_SERVER_TOKEN="1234567890987654321"
JOPLIN_RESSOURCES_PATH="/home/pi/.config/joplin/resources/"
JOPLIN_LOGIN_REQUIRED=True # set to True only if you require a logged user for accessing the notes
JOPLIN_SYNC_PERIOD_S=86400 # once a day
JOPLIN_SYNC_INFO_FILE="/home/pi/.config/joplin/joplin_vieweb_sync_info"
JOPLIN_NOTES_HISTORY_DEPTH = 10

Edit joplinweb/urls.py and add joplin path (and the import directive):

from django.urls import include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('joplin/', include('joplin_vieweb.urls'))
]
python manage.py collectstatic
python manage.py migrate
python manage.py createsuperuser

And add the following path in joplinweb/urls.py:

urlpatterns = [
    ...
    path('accounts/', include('django.contrib.auth.urls')),
]

nginx stuff

sudo apt install nginx
sudo systemctl enable nginx
sudo systemctl start nginx
upstream daphne-backend {
    server localhost:8001;
}

server {
    server_name my.domain.com; # IMPORTANT FOR AUTO CONFIG BY CERTBOT
    client_max_body_size 50M; # to allow up to 50M uplaod files.
    listen 80 default_server;
    listen [::]:80 default_server;

    location / {
        try_files $uri @proxy_to_app;
    }
    location @proxy_to_app {
        proxy_pass http://daphne-backend;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
    }
    location /static {
        alias /home/pi/.joplin-vieweb/joplinweb/staticfiles;
    }
    location  /favicon.ico {
        alias /home/pi/.joplin-vieweb/joplinweb/staticfiles/joplinvieweb/img/favicon.ico;
    }

}
sudo ln -s /etc/nginx/sites-available/my.domain.com /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t # test configuration of nginx, useful to check our conf is OK
sudo systemctl reload nginx.service

Let's encypt stuff

Run everything

You may write systemd files so that everything is automatically launched at OS startup...
The daphne command line should be run in the folder containing manage.py, in the python venv created and activated at the beginning.

joplin server start&
daphne -p 8001 joplinweb.asgi:application&

Run joplin-vieweb at system startup

FYI, I did as follow, on debian based (raspberry). pi is the user used to launch the commands.
I use crontab @reboot to launch a script at startup. The script start a screen (sudo apt-get install screen) with 3 tabs:

sudo crontab -e

Add the line @reboot /bin/bash /home/pi/.joplin-vieweb/joplin_screen.sh
Then:

cd .joplin-vieweb/
wget -O joplin_screen.sh https://raw.githubusercontent.com/gri38/django-joplin_vieweb/master/env/joplin_screen.sh
sudo reboot

Upgrade

Warning

Upgrade: