1. 程式人生 > >CentOS用Nginx和OwnCloud搭建私有云盤

CentOS用Nginx和OwnCloud搭建私有云盤

1. 安裝 Nginx

具體安裝步驟見如下連結 :

2. 安裝 OwnCloud

download_pack

然後解壓到 CentOS 目錄下 , 例如 : /usr/local/owncloud

3. 安裝 PHP

安裝的版本最好是 PHP 5.6 版本以上 , 我是直接官網下載的原始碼包 , 編譯安裝 , 具體步驟見下連結 :

4. 配置 Nginx

我的 Nginx 安裝在 /usr/local/nginx 目錄 , 編輯配置檔案 /usr/local/nginx/conf/nginx.conf :

# vim /usr/local/nginx/conf/nginx.conf

http 節點下新增 upstream php-handler

節點和 server 節點 , 內容如下所示 :

我設定監聽的是 8080 埠

upstream php-handler {
    server    127.0.0.1:9000; 
    #server    unix:/var/run/php5-fpm.sock; 
} 

server {
    listen    8080; 
    server_name    cloud.example.com; 
    # Path to the root of your installation 
    root    /usr/local/owncloud; 
    # set max upload size 
    client_max_body_size    10G; 
    fastcgi_buffers    64    4K; 
    # Disable gzip to avoid the removal of the ETag header 
    gzip    off; 
    # Uncomment if your server is build with the ngx_pagespeed module 
    # This module is currently not supported. 
    #pagespeed    off; 
    rewrite    ^/caldav(.*)$    /remote.php/caldav$1 redirect; 
    rewrite    ^/carddav(.*)$    /remote.php/carddav$1 redirect;
    rewrite    ^/webdav(.*)$    /remote.php/webdav$1 redirect;
    index    index.php;
    error_page    403    /core/templates/403.php;
    error_page    404    /core/templates/404.php;
    location = /robots.txt {
        allow all; 
        log_not_found off; 
        access_log off; 
    } 
    location ~ ^/(?:\.htaccess|data|config|db_structure\.xml|README){
        deny all; 
    }
    location / {
        # The following 2 rules are only needed with webfinger 
        rewrite ^/.well-known/host-meta /public.php?service=host-meta last; 
        rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last; 
        rewrite ^/.well-known/carddav /remote.php/carddav/ redirect; 
        rewrite ^/.well-known/caldav /remote.php/caldav/ redirect; 
        rewrite ^(/core/doc/[^\/]+/)$ $1/index.html; 
        try_files $uri $uri/ /index.php; 
    }
    location ~ \.php(?:$|/) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$; 
        include fastcgi_params; 
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
        fastcgi_param PATH_INFO $fastcgi_path_info; 
        fastcgi_pass php-handler; 
    }
    # Optional: set long EXPIRES header on static assets 
    location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
          expires 30d; 
          # Optional: Don't log access to assets 
            access_log off; 
    } 
}

5. 啟動服務

需要將 OwnCloud 目錄給 Nginx 使用者授權 :

# chown -R nginx:nginx /usr/local/owncloud/

啟動 Nginx 和 PHP , 在瀏覽器輸入主機的 IP , 如 192.168.22.37:8080 , 會載入 OwnCloud 的初始化介面 , 如下圖所示 :

init_owncloud

輸入管理員的賬戶和密碼 , 點選完成 , 就會進入到雲盤主頁了