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:

.. code-block:: bash

   sudo apt-get install apache2

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

.. code-block:: apache

   <VirtualHost *:880>

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

.. code-block:: apache

    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.

.. code-block:: bash

    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:

.. code-block:: bash

    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:

.. code-block:: nginx

    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:

.. code-block:: bash

    sudo service nginx force-reload

Extras
------

-  `Zotero Reader <http://zoteroreader.com/>`__ - HTML5 client
-  `Zandy <https://github.com/ajlyon/zandy>`__ - Android Open Source
   client

