在非根域名下部署 Seahub

这份文档将说明如何在网站的非根文件夹下通过 Apache/Nginx 部署 Seafile。

注意: 请先阅读 Nginx 下配置 Seahub 或者 Apache 下配置 Seahub.

Nginx 下部署

首先更改 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

我们将使用 Nginx 来管理静态文件(js, css, etc), 所以将 SERVE_STATIC 设置为 False

可以自定义 MEDIA_URL 的值,但是确保结尾包含斜线。

因为要在 /seafile/ 目录下而不是根目录下部署 Seafile, 所以设置 SITE_ROOT 的值为 /seafile/

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

接下来设置 SERVICE_URLFILE_SERVER_ROOT 的值。

Apache 下部署

首先更改 seahub_settings.py 中一些变量的值:

  1. SERVE_STATIC = False
  2. MEDIA_URL = '/seafmedia/'
  3. SITE_ROOT = '/seafile/'

httpd.conf 文件中加入以下语句:

  1. FastCGIExternalServer /var/www/seahub.fcgi -host 127.0.0.1:8000
接下来配置 Apache,示例如下:
  1. ServerName www.example.com
  2. DocumentRoot /var/www
  3. Alias /seafmedia /home/user/haiwen/seafile-server-2.0.2/seahub/media
  4. RewriteEngine On
  5. #
  6. # seafile fileserver
  7. #
  8. ProxyPass /seafhttp http://127.0.0.1:8082
  9. ProxyPassReverse /seafhttp http://127.0.0.1:8082
  10. RewriteRule ^/seafhttp - [QSA,L]
  11. #
  12. # seahub
  13. #
  14. RewriteRule ^/(seafmedia.*)$ /$1 [QSA,L,PT]
  15. RewriteCond %{REQUEST_FILENAME} !-f
  16. RewriteRule ^/(seafile.*)$ /seahub.fcgi/$1 [QSA,L,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  17.  

请注意更改 Alias 的值为自己的文件路径。

更改 ccnet.conf 和 seahub_setting.py

更改 ccnet.conf

为使 Seafile 知道你所使用的域名,请更改 /data/haiwen/conf/ccnet.confSERVICE_URL 变量的值。

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

注意: 如果以后域名有所变动,请记得更改 SERVICE_URL.

更改 seahub_settings.py

更改 seahub_settings.pyFILE_SERVER_ROOT 的值

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

启动 Seafile 和 Seahub

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