天天看點

centos6.5下使用lnmp架構安裝nextcloud雲盤

最近兩年随着各大網盤紛紛關閉,百度雲也早早的就開始限速,檔案的安全也沒有保障。是以還不如自己搭建一個網盤。網上看了下,發現有一個nextcloud比較好用。支援多平台用戶端,支援分享,使用操作簡單。支援插件擴充,檔案預覽,線上協作。

  1. 安裝nginx
wget http://nginx.org/download/nginx-1.10.3.tar.gz
tar -zxf nginx-1.10.3.tar.gz && cd nginx-1.10.3
./configure --prefix=/usr/local/data/nginx --user=nginx --group=nginx --with-pcre --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
make && make install      

2.安裝配置php

yum install http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum --enablerepo=remi-php56 install php php-fpm php-mysql php-gd php-xml php-redis php-libs php-devel php-zlib php-mbstring      

nginx 和php-fpm 的運作使用者這裡使用nginx

vim /etc/php-fpm.conf
user = nginx
group = nginx
listen = 127.0.0.1:9000
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp      

3.安裝mysql

yum -y install mysql mysql-server
service mysqld start      

4.建庫,授權

CREATE DATABASE nextcloud_db;GRANT ALL ON nextcloud_db.* TO 'nextcloud'@'%' IDENTIFIED BY 'nextcloud'; //注意一定要加 "%",否則無法讓網絡讓任何人上傳檔案
FLUSH PRIVILEGES;      

5.安裝nextcloud

wget https://download.nextcloud.com/server/releases/nextcloud-10.0.2.zip --no-check-certificate
unzip nextcloud-10.0.2.zip
mv nextcloud /usr/local/data/nginx/html
/usr/local/data/nginx/html
chown -R nginx.nginx      

建立資料目錄,這裡建議資料目錄不要和web目錄放到一起

/usr/local/data/nginx/html/nextcloud/data      

6.申請證書

為了網盤的安全,有必要使用https 證書,這裡可以在阿裡雲背景申請免費的DV證書

7.配置nginx

建立虛拟主機檔案

cd /usr/local/data/nginx/conf
vim nextcloud.conf
upstream php-handler {
server 127.0.0.1:9000;
}server {listen 80;
server_name cloud.nextcloud.com;
return 301 https://$server_name$request_uri;}server {listen 443 ssl;server_name cloud.nextcloud.com;
ssl_certificate /usr/local/data/nginx/conf/nextcloud.crt;
ssl_certificate_key /usr/local/data/nginx/conf/nextcloud.key;
#添加如下header主要為了安全
add_header Strict-Transport-Security "max-age=15768000;includeSubDomains; preload;";add_header X-Content-Type-Options nosniff;add_header X-Frame-Options "SAMEORIGIN";add_header X-XSS-Protection "1; mode=block";add_header X-Robots-Tag none;add_header X-Download-Options noopen;add_header X-Permitted-Cross-Domain-Policies none;
#nextcloud代碼目錄
root /usr/local/data/nginx/html/nextcloud/;
location = /robots.txt {allow all;log_not_found off;access_log off;}
#為了支援user_webfinger app
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
#這兒是為了支援月曆和聯系人,建議加上
location = /.well-known/carddav {return 301 $scheme://$host/remote.php/dav;}location = /.well-known/caldav {return 301 $scheme://$host/remote.php/dav;}
#設定上傳檔案的最大大小,php也得修改
client_max_body_size 512M;fastcgi_buffers 64 4K;# Disable gzip to avoid the removal of the ETag headergzip off;
error_page 403 /core/templates/403.php;error_page 404 /core/templates/404.php;
#重要的:将所有請求轉發到index.php上
location / {rewrite ^ /index.php$uri;
}
#安全設定,禁止通路部分敏感内容
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {deny all;}location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {deny all;}location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {include fastcgi_params;fastcgi_split_path_info ^(.+\.php)(/.*)$;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param PATH_INFO $fastcgi_path_info;fastcgi_param HTTPS on;#Avoid sending the security headers twicefastcgi_param modHeadersAvailable true;fastcgi_param front_controller_active true;fastcgi_pass php-handler;fastcgi_intercept_errors on;fastcgi_request_buffering off;
}
#安全設定,禁止通路部分敏感内容
location ~ ^/(?:updater|ocs-provider)(?:$|/) {try_files $uri/ =404;index index.php;}
# 添加js和css檔案的緩存控制頭
location ~* \.(?:css|js)$ {try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
add_header Strict-Transport-Security "max-age=15768000;includeSubDomains; preload;";add_header X-Content-Type-Options nosniff;add_header X-Frame-Options "SAMEORIGIN";add_header X-XSS-Protection "1; mode=block";add_header X-Robots-Tag none;add_header X-Download-Options noopen;add_header X-Permitted-Cross-Domain-Policies none;
access_log off;}location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {try_files $uri /index.php$uri$is_args$args;
access_log off;}}      
vim nginx.conf
include nextcloud.conf;
service nginx start      

8.配置php上傳大小

vim /etc/php.ini
max_execution_time = 0
post_max_size = 512M
upload_max_filesize = 512M
service php-fpm start      

9.配置nextcloud

centos6.5下使用lnmp架構安裝nextcloud雲盤

10.nextcloud 配置redis緩存

使用Redis做記憶體緩存可以有效提升程式運作速度。

curl -O http://download.redis.io/releases/redis-3.2.8.tar.gz
tar -zxvf redis-3.2.8.tar.gz
cd redis-3.2.8/deps/
make geohash-int hiredis jemalloc linenoise lua
cd ..
make && make install
cd utils/
./install_server.sh      

配置redis

vim /etc/redis/6379.conf# requirepass foobared
requirepass ExpvUwNOk9XRawC8
bind 192.168.40.200      

啟動

redis-server /etc/redis/6379.conf      

配置nextcloud

cd /usr/local/nginx/html/nextcloud/config
vim config.php 
'memcache.local' => '\OC\Memcache\Redis',
'redis' => array(
'host' => '192.168.40.200',
'port' => 6379,
'password' => 'ExpvUwNOk9XRawC8',
),      

重新整理頁面

centos6.5下使用lnmp架構安裝nextcloud雲盤

設定定時

*/15 * * * * /usr/bin/php /usr/local/nginx/html/nextcloud/cron.php >/dev/null      

繼續閱讀