前些日子終於受夠了臃腫的 Nextcloud ,將其完全卸載,尋覓已久之后選擇了 Seafile 雲盤。之所以放棄 Nextcloud,大致有以下原因:
- 插件豐富,功能強大的同時帶來運行緩慢的問題
- PHP 執行長時間大內存任務時容易出錯
- iPhone 客戶端莫名閃退,Linux 客戶端無法打開
- Rclone 執行長時間文件讀取操作時會容易出錯,同第二條
綜上原因,雖然 Nextclud 有着完整的功能和完善的生態,但並不適合目前的我個人使用。
之后發現 Seafile 提供全平台客戶端,服務端安裝簡單,文檔齊全,實測功能也比較全,帶有 webdav ,使用 Python 運行速度也是不錯的,因此選擇 Seafile 做個人雲盤。
接下來介紹分兩部分:
- Seafile 雲盤一鍵安裝(使用官方提供的腳本)
- 配置域名並配置 SSL 加密通訊
Seafile 雲盤一鍵安裝
官方文檔提到「如果您是初次部署 Seafile 服務,我們建議您使用自動安裝腳本來快速部署一個 Seafile 服務。」
本人是第一次安裝 Seafile ,對於各項配置不是很熟悉,因此采用這種方式,更容易上手。開始前需保證服務器是干凈的。
第一步,獲取腳本
運行如下命令獲取腳本:
# 適用於 Seafile 7.1.x 及以上版本
## Ubuntu 18.04 (64bit):
wget https://raw.githubusercontent.com/haiwen/seafile-server-installer-cn/master/seafile-server-7.1-ubuntu-amd64-http
## CentOS 8 (64bit):
wget https://raw.githubusercontent.com/haiwen/seafile-server-installer-cn/master/seafile-server-7.1-centos-amd64-http
# 適用於 Seafile 6.x.x 及以上版本
## Ubuntu 16.04/18.04 (64bit):
wget https://raw.githubusercontent.com/haiwen/seafile-server-installer-cn/master/seafile-server-ubuntu-amd64-http
## CentOS 7 (64bit):
wget https://raw.githubusercontent.com/haiwen/seafile-server-installer-cn/master/seafile-server-centos-7-amd64-http
注:若服務器訪問 GitHub 有困難,可以考慮在較好網絡環境下訪問 GitHub ,拷貝腳本內容到服務器,之后手動運行。
第二步,運行腳本(以 7.1.0 為例)
# Ubuntu 16.04/18.04 (64bit):
bash seafile-server-ubuntu-amd64-http 7.1.0
# CentOS 7 (64bit):
bash seafile-server-centos-7-amd64-http 7.1.0
第三步,選擇安裝版本
在這里選擇 CE
版,即開源社區版。
完成后就可以看到打印輸出的結果,在這里記得保存 用戶名
和 密碼
,這是您的管理員賬戶。
至此,完成了最基本的 Seafile 部署,此時訪問 http://*.*.*.*
其中 *.*.*.*
是您服務器 IP 地址。之后輸入剛才輸出的用戶名和密碼,就可以進入 Seafile 了。
為 Seafile 配置 https 訪問
第一步,域名解析
將域名解析到服務器。
第二步,通過 OpenSSL 生成 SSL 數字認證
免費 Self-Signed SSL 數字證書用戶請看. 如果你是 SSL 付費證書用戶可跳過此步.
首先進入OpenSSL目錄,cd /etc/ssl
,之后運行如下命令。
openssl genrsa -out privkey.pem 2048
openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
第三步,修改 Nginx 配置文件
請修改 nginx 配置文件以使用 HTTPS,首先進入腳本自動配置的 Nginx 為 Seafile 反代的配置文件目錄:cd /etc/nginx/sites-enabled
主要修改兩個部分:
首先添加一個 server
用來將 http 重定向到 https:
server {
listen 80;
server_name cfile.frytea.com;
rewrite ^ https://$http_host$request_uri? permanent;#強制將http重定向到https
server_tokens off;
}
之后在原有監聽 80
端口為 http://127.0.0.1:8000/
服務代理的服務上進行修改,將 80
改為 443
,將域名改為您的域名,之后添加以下部分:
ssl on;
ssl_certificate /etc/ssl/cacert.pem;#cacert.pem 文件路徑
ssl_certificate_key /etc/ssl/privkey.pem; #privkey.pem 文件路徑
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:5m;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
server_tokens off;
用來制定證書路徑並配置一些必要的信息。
第四步,重新加載 Nginx
nginx -s reload
下面貼上本人的配置文件:
log_format seafileformat '$http_x_forwarded_for $remote_addr [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $upstream_response_time';
server {
listen 80;
server_name cfile.frytea.com;
rewrite ^ https://$http_host$request_uri? permanent;#強制將http重定向到https
server_tokens off;
}
server {
listen 443;
server_name cfile.frytea.com;
proxy_set_header X-Forwarded-For $remote_addr;
ssl on;
ssl_certificate /etc/ssl/cacert.pem;#cacert.pem 文件路徑
ssl_certificate_key /etc/ssl/privkey.pem; #privkey.pem 文件路徑
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:5m;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
server_tokens off;
location / {
proxy_passhttp://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_set_header X-Forwarded-Proto $scheme;
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 seafileformat;
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;
access_log /var/log/nginx/seafhttp.access.log seafileformat;
error_log/var/log/nginx/seafhttp.error.log;
}
location /media {
root /opt/seafile/seafile-server-latest/seahub;
}
location /seafdav {
proxy_passhttp://127.0.0.1:8080/seafdav;
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_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 1200s;
client_max_body_size 0;
access_log /var/log/nginx/seafdav.access.log seafileformat;
error_log/var/log/nginx/seafdav.error.log;
}
}
修改 Seafile 配置文件
現在 nginx 部分已經完成,但是 Seafile 並不知道,此時已經可以通過 https://your domain
訪問,下面還需要配置 Seafile 的默認域名:
修改 Seafile 配置文件:
vim /opt/seafile/conf/seahub_settings.py
在以下位置修改:
SERVICE_URL: https://www.myseafile.com
FILE_SERVER_ROOT: https://www.myseafile.com/seafhttp
最后重啟 Seafile 和 Seahub
cd /opt/seafile/seafile-server-latest
./seafile.sh restart
./seahub.sh restart
完成!最后記得管理員登入管理中心,在設置里配置一下新的地址。