Seafile is a great tool. Out of the box, it uses different ports but to make your router configuration easier and to make sure your connection won't be blocked by strict access points, you may want to use the default TCP port for HTTP traffic.
This article supposes you already installed Seafile on Synology using a chrooted Debian.
Create a virtual host
From the Synology NAS web interface, enable Web Station to be able to create additional websites. Open your control panel and activate the first option "Enable Web Station".
Then, connect to your Synology NAS using SSH and edit the configuration file.
Caution: one changed, you won't be able to edit website configuration through web interface. Doing so would remove this custom configuration.
Seafile virtual host on DSM 5.x
DSM 5.x uses Apache as web server.
~$ cat > /etc/httpd/sites-enabled-user/httpd-vhost.conf-user << EOF
<IfModule !fastcgi_module>
Include conf/extra/mod_fastcgi.conf
</IfModule>
AddHandler fastcgi-script .fcgi
NameVirtualHost *:80
<VirtualHost *:80>
ServerName seafile.mydomain.ext
RewriteEngine On
DocumentRoot /var/services/web/seafile
Alias /media /volume1/synodebian/home/seafile/mydomain.ext/seafile-server/seahub/media
# seafile httpserver
ProxyPass /seafhttp http://127.0.0.1:8082
ProxyPassReverse /seafhttp http://127.0.0.1:8082
RewriteRule ^/seafhttp - [QSA,L]
# seahub
RewriteRule ^/(media.*)$ /$1 [QSA,L,PT]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ /var/services/web/seafile/seahub.fcgi/$1 [QSA,L,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
FastCGIExternalServer /var/services/web/seafile/seahub.fcgi -host 127.0.0.1:8000
</VirtualHost>
EOF
Seafile virtual host on DSM 6.x
Starting with DSM 6, default web server is nginx. Apache is still available but nginx will give us the same performance while using less resources.
cat > /usr/local/etc/nginx/sites-enabled/server.webstation-vhost.conf << EOF
server { listen 80; listen [::]:80; listen 443 ssl; listen [::]:443 ssl; server_name seafile.mydomain.ext; root /volume1/web/seafile; proxy_set_header X-Forwarded-For $remote_addr; location ^~ /.well-known/acme-challenge { root /var/lib/letsencrypt; default_type text/plain; } location / { fastcgi_pass 127.0.0.1:8000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param HTTPS on; fastcgi_read_timeout 36000; if ($scheme = http) { rewrite ^ https://$http_host$request_uri? permanent; # force redirect http to https } } location /seafhttp { rewrite ^/seafhttp(.*)$ $1 break; proxy_pass http://127.0.0.1:8082; client_max_body_size 0; proxy_connect_timeout 36000s; proxy_read_timeout 36000s; proxy_send_timeout 36000s; send_timeout 36000s; } location /media { alias /volume1/synodebian/home/seafile/mydomain.ext/seafile-server/seahub/media; } } EOF
Virtual host configuration details
Seafile uses two ports: port 8000 is for seahub, Seafile web interface. Port 8082 is used by Seafile server for file transfer. On top of directing request to these two ports, the virtual host will also serve static content.
We might have other web services on the synology so we create a virtual host with a specific fqdn. Default behavior is to send requests to seahub, defined as an external FastCGI server on port 8000. This means document root doesn't have to exist. The seahub.fcgi file also doesn't exist, it is just a reference to the FastCGI server directive. All static files are prefixed by "/media" path. There is no point having the FastCGI server servicing these files as the web server can do it directly. To identify requests to be handled by Seafile server, we decide to direct all path starting with "/seafhttp" to port 8082. This time we use a reverse proxy since seafile server doesn't support FastCGI.
Having enabled user-specific websites, we lost the previous behavior, that is redirect default HTTP requests to Synology admin interface. This behavior can be restored using a simple php script.
~$ mv /var/services/web/index.html /var/services/web/index_bak.html
~$ cat > /var/services/web/index.php << EOF
<?php
header('Location: http://synology.mydomain.ext:5000/');
EOF
Update seafile configuration
Seafile isn't aware of this new configuration. We have to update seahub configuration. Chroot into Debian and edit the file /home/seafile/mydomain.ext/seahub_settings.py to add this line:
FILE_SERVER_ROOT = 'http://seafile.mydomain.ext/seafhttp'
There is no need to configure the MEDIA_URL since we're using the default "/media" path.
Seahub also has to be started as a FastCGI server instead of an HTTP server. This require a new package
~$ aptitude install python-flup
Once installed, seahub can be started using the extra "--fastcgi" command line parameter. Create a new script to start Seafile:
~$ cat > /home/seafile/mydomain.ext/start_seafile.sh << EOF
export LD_LIBRARY_PATH=/usr/local/lib
seafile-admin start --fastcgi
EOF
chmod +x /home/seafile/mydomain.ext/start_seafile.sh
If you initially installed Seafile using previous article, your Seafile should automatically starts with your NAS whenever you need to reboot it.