Seafile on Nginx with uWSGI
I’ve been using Seafile as my personal cloud storage for quite some time now and it’s working really really well. Since I’ve departed quite a bit from the standard setup instructions for the web frontend (Seahub) I’m going to document the setup a tiny little bit.
For complete Seafile setup instructions that include all components and not only the web frontend please refer to the Seafile Server Manual.
Running Seahub as a WSGI application
The standard setup instructions recommend to run Seahub behind Nginx as a
FastCGI application. However internally Seahub is actually a WSGI application
which is the standard way to communicate with Python based web-applications.
Since I’m using uWSGI for
managing and running several other services already I opted to skip the FastCGI
wrapper in front of Seahub and let uWSGI start the web application with the
correct environment instead. This also means seahub.sh
is not used anymore.
The configuration I use for uWSGI and Seafile Server 3.1.6 looks like this:
/etc/uwsgi/apps-available/seafile.ini
[uwsgi]
plugins = python
uid = seafile
gid = seafile
topdir = /srv/seafile
env = CCNET_CONF_DIR=%(topdir)/ccnet
env = SEAFILE_CONF_DIR=%(topdir)/seafile-data
env = SEAHUB_LOG_DIR=%(topdir)/logs
installpath = /srv/seafile/seafile-server-latest
env = PYTHONPATH=%(installpath)/seahub:%(installpath)/seahub/thirdpart: \
%(installpath)/seafile/lib64/python2.6/site-packages
env = DJANGO_SETTINGS_MODULE=seahub.settings
module = seahub.wsgi:application
Most environment variables set here are normally set in seahub.sh
before
starting the Python-based HTTP- or FastCGI-Server. The job of configuring the
environment is now done by uWSGI and the above configuration file instead.
For Python 2.7 the PYTHONPATH
contents obviously need to be adapted.
The only exception in this configuration is DJANGO_SETTINGS_MODULE
which is
normally set inside seahub/wsgi.py
early on. Unfortunately this did not seem
to work when running the application from uWSGI (probably since the app cannot
permanently modify the environment) so I had to set this inside the uWSGI
configuration file.
Configuring Nginx
For Nginx the configuration is almost identical to the
Seafile FastCGI setup
documented in the manual. The only change is that the root location element is
a lot simpler and uses uwsgi_pass
instead of fastcgi_pass
.
/etc/nginx/sites-available/seafile.conf
server {
listen 80;
server_name seafile.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name seafile.example.com;
location / {
include uwsgi_params;
uwsgi_pass unix:/var/run/uwsgi/app/seafile/socket;
}
location /seafhttp {
rewrite ^/seafhttp(.*)$ $1 break;
proxy_pass http://127.0.0.1:8082;
client_max_body_size 0;
}
location /media {
root /srv/seafile/seafile-server-latest/seahub;
}
}