Config Seahub with Nginx

Deploy Seahub/FileServer with Nginx

Seahub is the web interface of Seafile server. FileServer is used to handle raw file uploading/downloading through browsers. By default, it listens on port 8082 for HTTP requests.

Here we deploy Seahub and FileServer with reverse proxy. We assume you are running Seahub using domain seafile.example.com.

This is a sample Nginx config file.

In Ubuntu 16.04, you can add the config file as follows:

  1. create file /etc/nginx/sites-available/seafile.conf
  2. Delete /etc/nginx/sites-enabled/default: rm /etc/nginx/sites-enabled/default
  3. Create symbolic link: ln -s /etc/nginx/sites-available/seafile.conf /etc/nginx/sites-enabled/seafile.conf
  1. server {
  2. listen 80;
  3. server_name seafile.example.com;
  4. proxy_set_header X-Forwarded-For $remote_addr;
  5. location / {
  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_read_timeout 1200s;
  12. # used for view/edit office file via Office Online Server
  13. client_max_body_size 0;
  14. access_log /var/log/nginx/seahub.access.log;
  15. error_log /var/log/nginx/seahub.error.log;
  16. }
  17. # If you are using [FastCGI](http://en.wikipedia.org/wiki/FastCGI),
  18. # which is not recommended, you should use the following config for location `/`.
  19. #
  20. # location / {
  21. # fastcgi_pass 127.0.0.1:8000;
  22. # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  23. # fastcgi_param PATH_INFO $fastcgi_script_name;
  24. #
  25. # fastcgi_param SERVER_PROTOCOL $server_protocol;
  26. # fastcgi_param QUERY_STRING $query_string;
  27. # fastcgi_param REQUEST_METHOD $request_method;
  28. # fastcgi_param CONTENT_TYPE $content_type;
  29. # fastcgi_param CONTENT_LENGTH $content_length;
  30. # fastcgi_param SERVER_ADDR $server_addr;
  31. # fastcgi_param SERVER_PORT $server_port;
  32. # fastcgi_param SERVER_NAME $server_name;
  33. # fastcgi_param REMOTE_ADDR $remote_addr;
  34. # fastcgi_read_timeout 36000;
  35. #
  36. # client_max_body_size 0;
  37. #
  38. # access_log /var/log/nginx/seahub.access.log;
  39. # error_log /var/log/nginx/seahub.error.log;
  40. # }
  41. location /seafhttp {
  42. rewrite ^/seafhttp(.*)$ $1 break;
  43. proxy_pass http://127.0.0.1:8082;
  44. client_max_body_size 0;
  45. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  46. proxy_connect_timeout 36000s;
  47. proxy_read_timeout 36000s;
  48. proxy_send_timeout 36000s;
  49. send_timeout 36000s;
  50. }
  51. location /media {
  52. root /home/user/haiwen/seafile-server-latest/seahub;
  53. }
  54. }

Nginx settings client_max_body_size is by default 1M. Uploading a file bigger than this limit will give you an error message HTTP error code 413 (“Request Entity Too Large”).

You should use 0 to disable this feature or write the same value than for the parameter max_upload_size in section [fileserver] of seafile.conf. Client uploads are only partly effected by this limit. With a limit of 100 MiB they can safely upload files of any size.

Tip for uploading very large files (> 4GB): By default Nginx will buffer large request bodies in temp files. After the body is completely received, Nginx will send the body to the upstream server (seaf-server in our case). But it seems when the file size is very large, the buffering mechanism dosen’t work well. It may stop proxying the body in the middle. So if you want to support file uploads larger than 4GB, we suggest to install Nginx version >= 1.8.0 and add the following options to Nginx config file:

  1. location /seafhttp {
  2. ... ...
  3. proxy_request_buffering off;
  4. }

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, protocol and port you choose. You can also modify SERVICE_URL via web UI in “System Admin->Settings”. (Warning: If you set the value both via Web UI and ccnet.conf, the setting via Web UI will take precedence.)

  1. SERVICE_URL = http://seafile.example.com

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. You can also modify FILE_SERVER_ROOT via web UI in “System Admin->Settings”. (Warning: if you set the value both via Web UI and seahub_settings.py, the setting via Web UI will take precedence.)

  1. FILE_SERVER_ROOT = 'http://seafile.example.com/seafhttp'

Start Seafile and Seahub

  1. ./seafile.sh start
  2. ./seahub.sh start # or "./seahub.sh start-fastcgi" if you're using fastcgi