---
layout: post
title:  "Zotero"
date:   2014-12-09 12:12:12
tags: zotero webdav nginx apache
---
[Zotero](https://www.zotero.org/) is an Open Source tool that lets you organise your bibliography, syncing it with the cloud.
Unlike other alternatives such as [Mendeley](http://www.mendeley.com), Zotero can upload the attachments and data to a private cloud via WebDav.

If you use nginx as your web server, know that even though it provides partial support for webdav, Zotero needs more than that.
Hence, you will need another webdav server, and optionally let nginx proxy to it.
This short post provides the basics to get that set-up working under Debian/Ubuntu.

## Setting up Apache

First we need to install Apache:

    sudo apt-get install apache2

Change the head of "/etc/apache2/sites-enabled/000-default" to:

    <VirtualHost *:880>

Then, create a file /etc/apache2/sites-available/webdav:

    Alias /dav /home/webdav/dav
    <Location /dav>
        Dav on
        Order Allow,Deny
        Allow from all
        Dav On
        Options +Indexes
        AuthType Basic
        AuthName DAV
        AuthBasicProvider file
        AuthUserFile /home/webdav/.htpasswd
        Require valid-user
    </Location>

Ideally, you want your webdav folders to be private, adding authentication to them.
So you need to create the webdav and zotero users and add the passwords to an htpasswd file.
Even though you could use a single user, since you will be configuring several clients with your credentials I encourage you to create the zotero user as well.
This way you can always change the password for zotero without affecting any other application using webdav.

    sudo adduser webdav
    sudo htpasswd -c /home/webdav/.htpasswd webdav
    sudo htpasswd /home/webdav/.htpasswd zotero
    sudo mkdir -p /home/webdav/dav/zotero

Enable the site and restart apache:

    sudo a2enmod webdav
    sudo a2enmod dav_fs
    sudo a2ensite webdav
    sudo service apache2 restart

At this point everything should be working at http://\<your_host\>:880/dav/zotero

## Setting up NGINX
After the Apache side is working, we can use nginx as a proxy to get cleaner URIs.
In your desired site/location, add this:

    location /dav {
        client_max_body_size 20M;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:880;
    }

Now just reload nginx:

    sudo service nginx force-reload

## Extras

* [Zotero Reader](http://zoteroreader.com/) - HTML5 client
* [Zandy](https://github.com/ajlyon/zandy) - Android Open Source client
