Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習 Linux

CentOS 6.8 + Nginx + Python 2.7 架設 Seafile 私有雲筆記

這篇是實作過程的隨手筆記,記錄在 CentOS 6.8 上搭配 Nginx 與 Python 2.7.13 部署 Seafile 私有雲的完整歷程,包含踩到的坑與繞道方案。

一、前置準備

先完成 MySQL 的安裝與設定(細節從略),再閱讀官方中文手冊 https://manual-cn.seafile.com,依步驟逐項操作。前幾步大致順利,問題出在啟動階段。

二、啟動 Seafile 與 Seahub

./seafile.sh start          # 啟動 Seafile 服務
./seahub.sh start <port>    # 啟動 Seahub,預設 8000

執行 Seahub 時出現找不到 ssl 模組的錯誤,多方查資料仍無法排除,於是暫時放棄直接啟動,改由 Nginx 反向代理/FastCGI 對外提供服務。

三、以 Nginx 配置 Seahub

server {
    listen 80;                        # 依實際使用埠號調整
    server_name www.myseafile.com;    # 依實際情況調整

    proxy_set_header X-Forwarded-For $remote_addr;

    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;
        access_log /var/log/nginx/seahub.access.log;
        error_log  /var/log/nginx/seahub.error.log;
    }

    location /seafhttp {
        rewrite ^/seafhttp(.*)$ $1 break;
        proxy_pass https://127.0.0.1:8082;
        client_max_body_size 0;
        proxy_connect_timeout 36000s;
        proxy_read_timeout 36000s;
    }

    location /media {
        root /home/user/haiwen/seafile-server-latest/seahub;  # 改為自己的 seahub 路徑
    }
}

四、以 FastCGI 模式啟動

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

啟動成功後用瀏覽器訪問對應位址,測試可正常登入與上傳。

五、開放 MySQL 遠端連線

mysql -u root -p

mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> select host, user from user;
mysql> flush privileges;

host 從 localhost 改為 % 代表允許任意來源;若只想放行特定 IP,可改成例如 192.168.1.123。生產環境請搭配防火牆限制來源,並建立專用帳號而非直接用 root。

六、遇到的問題與心得

最大的障礙是 Python 的 _ssl 模組缺失,導致 seahub.sh start 無法使用,只能走 FastCGI 路線;根本解法是重新編譯安裝帶 ssl 支援的 Python。過程中大量查閱 Linux 指令與 Nginx 設定,雖然辛苦,但也把基礎打得更扎實。

Copyright © Linux教程網 All Rights Reserved