2014年9月17日星期三

Apache 下配置 Seahub

准备工作

  1. Ubuntu 下安装python-flup库:
     sudo apt-get install python-flup
     
  2. Ubuntu 下安装和启用 mod_fastcgi 和 mod_rewrite :
     sudo apt-get install libApache2-mod-fastcgi
     sudo a2enmod rewrite
     sudo a2enmod fastcgi
     
  3. 启用 Apache proxy
     sudo a2enmod proxy_http
     
Windows 下, 首先下载mod_fastcgi-*.dll并将它放置在你的组件目录下. 在 debian/raspbian 环境下安装 fcgi 请参考这里

Apache 环境下部署 Seahub/FileServer

Seahub 是 Seafile 服务器的网站界面. FileServer 用来处理浏览器端文件的上传与下载. 默认情况下, 它在 8082 端口上监听 HTTP 请求.
这里我们通过 fastcgi 部署 Seahub, 通过反向代理(Reverse Proxy)部署 FileServer. 我们假设你已经将 Seahub 绑定了域名"www.myseafile.com".
首先编辑你的 Apache 配置文件.根据你的 Linux 版本, 你需要在文件末尾增加以下语句:
Apache2.conf, for ubuntu/debian:
FastCGIExternalServer /var/www/seahub.fcgi -host 127.0.0.1:8000
httpd.conf, for centos/fedora:
FastCGIExternalServer /var/www/html/seahub.fcgi -host 127.0.0.1:8000
httpd.conf, for Windows:
LoadModule fastcgi_module modules/mod_fastcgi-2.4.6-AP22.dll
LoadModule rewrite_module modules/mod_rewrite.so
FastCGIExternalServer e:/seafile-server-1.7.1/seahub/seahub.fcgi -host 127.0.0.1:8000
注意, seahub.fcgi只是一个位置标识符, 你并不需要在你的系统中新建这个文件夹.
二, 修改 Apache 配置文件: (sites-enabled/000-default) for ubuntu/debian (vhost.conf) for centos/fedora
<VirtualHost *:80>
  ServerName www.myseafile.com
  DocumentRoot /var/www
  Alias /media  /home/user/haiwen/seafile-server-latest/seahub/media

  RewriteEngine On

  #
  # seafile fileserver
  #
  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 ^(.*)$ /seahub.fcgi$1 [QSA,L,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</VirtualHost>

修改 ccnet.conf 和 seahub_setting.py

修改 ccnet.conf

你需要在/data/haiwen/ccnet/ccnet.confSERVICE_URL字段中自定义域名。
SERVICE_URL = http://www.myseafile.com
注意:如果你改变了 Seahub 的域名,也需要同步更改SERVICE_URL.

修改 seahub_settings.py

请在seahub_settings.py新增一行,设定FILE_SERVER_ROOT的值
FILE_SERVER_ROOT = 'http://www.myseafile.com/seafhttp'

启动 Seafile 和 Seahub

sudo service Apache2 restart
./seafile.sh start
./seahub.sh start-fastcgi

升级 Seafile 服务器注意事项

升级时, 除了常规操作外,还需增加一步操作: '''在 nginx/apache 配置中更新静态文件路径'''. 例如, 假设你正在将服务器从 1.3.0 升级到 1.4.0, 那么你需要:
  Alias /media  /home/user/haiwen/seafile-server-1.4.0/seahub/media
小贴士:
你可以创建一个符号链接seafile-server-latest, 并将它指向当前 Seafile 服务器文件夹(在2.1.0及其后续服务器版本中,e setup-seafile.sh脚本程序会自动创建). 之后, 每次你运行一个升级脚本, 脚本都会自动为seafile-server-latest创建符号链接并将其指向最新版本服务器的文件夹.
通过如下语句实现:
    location /media {
        root /home/user/haiwen/seafile-server-latest/seahub;
    }
这样,以后在你升级 Seafile 服务器的时候,不必每次都去更新 Nginx 配置.

其他说明

阅读Seafile 组件会帮你更好的理解 Seafile
在 Seafile 服务器端有两个组件:Seahub 和 FileServer. FileServer 通过监听 8082 端口处理文件的上传与下载. Seahub 通过监听 8000 端口负责其他的WEB页面. 但是在 https 下, Seahub 应该通过 fastcgi 模式监听8000端口 (运行./seahub.sh start-fastcgi). 而且在 fastcgi 模式下, 如果直接访问http://domain:8000时,会返回错误页面.
当一个用户访问https://domain.com/home/my/时, Apache 接受到访问请求后,通过 fastcgi 将其转发至 Seahub. 可通过以下配置来实现:
#
# seahub
#
RewriteRule ^/(media.*)$ /$1 [QSA,L,PT]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(seahub.*)$ /seahub.fcgi/$1 [QSA,L,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
FastCGIExternalServer /var/www/seahub.fcgi -host 127.0.0.1:8000
当一个用户在 Seahub 中点击文件下载链接时, Seahub 读取FILE_SERVER_ROOT的值,并将其用户重定向到https://domain.com/seafhttp/xxxxx/https://domain.com/seafhttpFILE_SERVER_ROOT的值. 这里,FILE_SERVER 表示是 Seafile 中只负责文件上传与下载的的 FileServer 组件.
当 Apache 在 https://domain.com/seafhttp/xxxxx/接收到访问请求后, 它把请求发送到正在监听 127.0.0.1:8082 的 FileServer 组件, 可通过以下配置来实现:
ProxyPass /seafhttp http://127.0.0.1:8082
ProxyPassReverse /seafhttp http://127.0.0.1:8082
RewriteRule ^/seafhttp - [QSA,L]

没有评论:

发表评论