Deploy Seahub at Non-root domain

This documentation will talk about how to deploy Seafile Web using Apache/Nginx at Non-root directory of the website(e.g., www.example.com/seafile/). Please note that the file server path will still be e.g. www.example.com/seafhttp (rather than www.example.com/seafile/seafhttp) because this path is hardcoded in the clients.

Note: We assume you have read Deploy Seafile with nginx or Deploy Seafile with apache.

Configure Seahub

First, we need to overwrite some variables in seahub_settings.py:

  1. SERVE_STATIC = False
  2. MEDIA_URL = '/seafmedia/'
  3. COMPRESS_URL = MEDIA_URL
  4. STATIC_URL = MEDIA_URL + 'assets/'
  5. SITE_ROOT = '/seafile/'
  6. LOGIN_URL = '/seafile/accounts/login/' # NOTE: since version 5.0.4

The webserver will serve static files (js, css, etc), so we just disable SERVE_STATIC.

MEDIA_URL can be anything you like, just make sure a trailing slash is appended at the end.

We deploy Seafile at /seafile/ directory instead of root directory, so we set SITE_ROOT to /seafile/.

Modify ccnet.conf and seahub_setting.py

Modify ccnet.conf

You need to modify the value of SERVICE_URL in ccnet.conf
to let Seafile know the domain you choose.

  1. SERVICE_URL = http://www.myseafile.com/seafile

Note: If you later change the domain assigned to seahub, you also need to change the value of SERVICE_URL.

Modify seahub_settings.py

You need to add a line in seahub_settings.py to set the value of FILE_SERVER_ROOT

  1. FILE_SERVER_ROOT = 'http://www.myseafile.com/seafhttp'

Note: The file server path MUST be /seafhttp because this path is hardcoded in the clients.

Webserver configuration

Deploy with Nginx

Then, we need to configure the Nginx:

  1. server {
  2. listen 80;
  3. server_name www.example.com;
  4. proxy_set_header X-Forwarded-For $remote_addr;
  5. location /seafile {
  6. proxy_pass http://127.0.0.1:8000;
  7. proxy_set_header Host $host;
  8. proxy_set_header X-Real-IP $remote_addr;
  9. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  10. proxy_set_header X-Forwarded-Host $server_name;
  11. proxy_set_header X-Forwarded-Proto $scheme;
  12. proxy_read_timeout 1200s;
  13. # used for view/edit office file via Office Online Server
  14. client_max_body_size 0;
  15. access_log /var/log/nginx/seahub.access.log;
  16. error_log /var/log/nginx/seahub.error.log;
  17. }
  18. location /seafhttp {
  19. rewrite ^/seafhttp(.*)$ $1 break;
  20. proxy_pass http://127.0.0.1:8082;
  21. client_max_body_size 0;
  22. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  23. proxy_connect_timeout 36000s;
  24. proxy_read_timeout 36000s;
  25. }
  26. location /seafmedia {
  27. rewrite ^/seafmedia(.*)$ /media$1 break;
  28. root /home/user/haiwen/seafile-server-latest/seahub;
  29. }
  30. }

Deploy with Apache

Here is the sample configuration:

  1. <VirtualHost *:80>
  2. ServerName www.example.com
  3. DocumentRoot /var/www
  4. Alias /seafmedia /home/user/haiwen/seafile-server-latest/seahub/media
  5. <Location /seafmedia>
  6. ProxyPass !
  7. Require all granted
  8. </Location>
  9. RewriteEngine On
  10. #
  11. # seafile fileserver
  12. #
  13. ProxyPass /seafhttp http://127.0.0.1:8082
  14. ProxyPassReverse /seafhttp http://127.0.0.1:8082
  15. RewriteRule ^/seafhttp - [QSA,L]
  16. #
  17. # seahub
  18. #
  19. SetEnvIf Request_URI . proxy-fcgi-pathinfo=unescape
  20. SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
  21. ProxyPass /seafile fcgi://127.0.0.1:8000/seafile
  22. </VirtualHost>

We use Alias to let Apache serve static files, please change the second argument to your path.

Clear the cache

By default, Seahub caches some data like the link to the avatar icon in /tmp/seahub_cache/ (unless memcache is used). We suggest to clear the cache after seafile has been stopped:

  1. rm -rf /tmp/seahub_cache/

For memcache users, please purge the cache there instead by restarting your memcached server.

Start Seafile and Seahub

  1. ./seafile.sh start
  2. ./seahub.sh start