Set up WebDAV using Nginx for use with Zotero

Zotero Sync comes with a free 300mb, and when that space is too low and you don’t want to pay a subscription, you can use an existing nginx setup to easily use a server you own to store your Zotero documents.

Step 1

Create an SSL cert using certbot

sudo certbot certonly -d your.site.com

To this prompt:

How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Nginx Web Server plugin (nginx)
2: Spin up a temporary webserver (standalone)
3: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-3] then [enter] (press 'c' to cancel): 

Choose nginx (1).

It should complete successfully.

Step 2

Make an htpasswd file for basic authentication, and place it somewhere.

Step 3

Add a new server block to your sites-available config

server {
    server_name your.site.com;
    listen [::]:443;
    ssl on;
    listen 443 ssl;
    root /folder/nginx/user/owns/;
    ssl_certificate /etc/letsencrypt/live/your.site.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your.site.com/privkey.pem; 
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    auth_basic "zotero";
    auth_basic_user_file /path/to/.htpasswd;
    location /zotero {
        root                  /folder/nginx/user/owns;
        client_body_temp_path /tmp;

        dav_methods PUT DELETE MKCOL COPY MOVE;
        dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK;
        create_full_put_path  on;
        dav_access            group:rw  all:r;
        client_max_body_size 1G;
    }

    location ~ /\.ht {
      deny all;
    }
}

Step 4

Set up WebDAV in Zotero:

Zotero WebDAV Image