树莓派安装seafile

  1. 从官网下载seafile-server,解压上传到树莓派。
  2. 安装依赖:apt-get install python2.7 libpython2.7 python-setuptools python-pil python-ldap python-urllib3 sqlite3
  3. 插上额外得硬盘,假设其位置为/media/pi/cloud,将seafile-server中的文件都移动到/media/pi/cloud/seafile文件夹中,然后运行./setup-seafile.sh,安装过程需要输入名字、ip等。
  4. 如果通过ip无法访问,可以修改gunicorn.conf中bind参数,重启
  5. 添加公网映射(在路由器中添加映射),同时在seafile系统管理中->设置中,修改SERVICE_URL、FILE_SERVER_ROOT为公网地址
  6. 安装nginx反代sudo apt-get install nginx
  7. 创建文件/etc/nginx/sites-available/seafile.conf,拷贝以下内容,其中ip地址和端口号是公网ip地址和端口,在路由器中映射到内网ip地址和内网端口80
  8. 删除 /etc/nginx/site-enabled/default,rm /etc/nginx/sites-enabled/default
  9. 创建符号链接:ln -s /etc/nginx/sites-available/seafile.conf /etc/nginx/sites-enabled/seafile.conf
  10. server {
        listen 80;
        server_name seafile.example.com;
    
        proxy_set_header X-Forwarded-For $remote_addr;
    
        location / {
             proxy_pass         http://127.0.0.1:8000;
             proxy_set_header   Host $host;
             proxy_set_header   X-Real-IP $remote_addr;
             proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header   X-Forwarded-Host $server_name;
             proxy_read_timeout  1200s;
    
             # used for view/edit office file via Office Online Server
             client_max_body_size 0;
    
             access_log      /var/log/nginx/seahub.access.log;
             error_log       /var/log/nginx/seahub.error.log;
        }
    
    # If you are using [FastCGI](http://en.wikipedia.org/wiki/FastCGI),
    # which is not recommended, you should use the following config for location `/`.
    #
    #    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_read_timeout 36000;
    #
    #         client_max_body_size 0;
    #
    #         access_log      /var/log/nginx/seahub.access.log;
    #          error_log       /var/log/nginx/seahub.error.log;
    #    }
    
        location /seafhttp {
            rewrite ^/seafhttp(.*)$ $1 break;
            proxy_pass http://127.0.0.1:8082;
            client_max_body_size 0;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    
            proxy_connect_timeout  36000s;
            proxy_read_timeout  36000s;
            proxy_send_timeout  36000s;
            proxy_request_buffering off;
            send_timeout  36000s;
        }
        location /media {
            root /home/user/haiwen/seafile-server-latest/seahub;
        }
    }
  11. 打开80端口防火墙:安装apt-get install ufwufw enableufw allow 80
  12. 此时通过外网ip访问,发现无法加载css,查看nginx日志cat /var/log/nginx/error.log,发现是权限问题,解决方法:vi /etc/nginx/nginx.conf,将第一行的user改为pi,重启nginx服务。
  13. 去花生壳注册动态域名,在路由器中添加动态域名解析,然后将nginx配置中的IP地址改成域名,即可通过域名访问,同时要修改SERVICE_URL、FILE_SERVER_ROOT为域名。
  14. 由于路由器不具有端口回流的功能,内网不能通过域名访问,所以用树莓派自建dns服务器,将域名转换为局域网内地址:
    • sudo apt-get install dnsmasq
    • 编辑配置文件:sudo vi /etc/dnsmasq.conf,192.168.1.37是树莓派局域网内地址,address即域名解析
      • resolv-file=/etc/my_dns.conf 
        strict-order 
        cache-size=10000 
        listen-address=127.0.0.1,192.168.1.37 
        address=/域名/192.168.1.37
    • 编辑文件:sudo vi /etc/my_dns.conf
      • nameserver 127.0.0.1 
        nameserver 119.29.29.29 
        nameserver 182.254.116.116
    • 将路由器的dns设置为树莓配局域网地址192.168.1.37
       

发表评论

电子邮件地址不会被公开。 必填项已用*标注