Nextcloud私有云盘搭建教程
环境:
操作系统:centos_7.6 x86-64
mariadb:5.5.56-Mariadb
php:php 7.0.31
nextcloud:nextcloud-13.0.5
确保机器正常连网
……
1.安装NGINX
安装 epel源
yum instlal -y epel-release
yum instlal -y nginx
启动nginx
systemctl start nginx
systemctl enable nginx
2.安装mariadb
更换国内的yum源
cd /etc/yum.repo.d/
wget -O Centos-Base.repo http://mirrors.aliyum.com/repo/Centos-7.repo
yum clean all && yum makecache
如果是最小化安装的操作系统,是没有wget工具的,所发需要安装一下wget
yum install -y wget
安装mariadb
yum install -y mariadb-server mariadb
systemctl start mariadb
systemctl enable mariadb
设置数据库密码
echo 'skip-grant-tables'>>/etc/my.cnf
systemctl restart maridb
mysql -u root
MariaDB [(none)]> use mysql;
MariaDB [mysql]> select user, password, host from user;
MariaDB [mysql]> update user set password=password('这里输入自己的密码') where User="root" and Host="localhost";
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> exit
注释掉/etc/my.cnf最后一行,重启数据库
systemctl restart mariadb
systemctl enable mariadb
3.安装PHP
安装php及依赖插件
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
安装php环境
yum install yum-utils
yum-config-manager --enable remi-php70 [Install PHP 7.0]
yum-config-manager --enable remi-php71 [Install PHP 7.1]
yum-config-manager --enable remi-php72 [Install PHP 7.2]
安装扩展
yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo \
php-devel php-pear php-gd php-opcache php-cli php-pdo php-process php-pecl-apcu php-mcrypt \
php-mysql php-fpm php-pecl-memcached php-common php-xml php-mbstring php-pecl-igbinary-devel
所有的组件都要安装哦,太长可以先复制到记事本,然后再复制到xshell或者mobaxter等远程工具。
制作签名和SSL证书
mkdir /etc/nginx/cert/
cd /etc/nginx/cert/
openssl rep -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key
赋权限
chmod 600 /etc/nginx/cert/*
chmod 700 /etc/nginx/cert/
4.下载Nextcloud
下载13.0.2版本
cd /opt/
wget https://download.nextcloud.com/server/releases/nextcloud-13.0.5.zip
unzip nextcloud-13.0.5.zip
cd /usr/share/nginx/html
rm -rf *
cp -R /op/nextcloud/* .
chown -R nginx:nginx /usr/share/nginx/html
5.配置php和nginx
配置PHP
vim /etc/php-fpm.d/www.conf
-------------------------------------
user = nginx //将用户和组都改为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
-------------------------------------
# 创建session文件夹
mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/
配置Nginx
cd /etc/nginx/conf.d/
vim nextcloud.conf
-------------------------------------
upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name localhost;
# enforce https
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/nginx/cert/nextcloud.crt;
ssl_certificate_key /etc/nginx/cert/nextcloud.key;
# Add headers to serve security related headers
# Before enabling Strict-Transport-Security headers please read into this
# topic first.
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;
# Path to the root of your installation
root /usr/share/nginx/html/; //这个地址要注意,是主页的保存地址,也就是解压nextcloud的地址
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this 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;
}
# set max upload size
client_max_body_size 10240M; # 上传文件最大限制,php.ini中也要修改,最后优化时会提及。
fastcgi_buffers 64 4K;
# Disable gzip to avoid the removal of the ETag header
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.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 twice
fastcgi_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;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~* \.(?:css|js)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
# Add headers to serve security related headers (It is intended to
# have those duplicated to the ones above)
# Before enabling Strict-Transport-Security headers please read into
# this topic first.
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;
# Optional: Don't log access to assets
access_log off;
}
location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
# Optional: Don't log access to other assets
access_log off;
}
}
注释掉默认配置文件里的80端口模块
vim /etc/nginx/nginx.conf
#server {
# listen 80 default_server;
# listen [::]:80 default_server;
# server_name _;
# root /usr/share/nginx/html;
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
# location / {
# }
# error_page 404 /404.html;
# location = /40x.html {
# }
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
#}
6.关掉SELINUX与防为墙
setenforce 0
sed -i "s/=enforcing/=disabled/g" /etc/selinux/config
7.web访问&&安装
默认80,打开浏览器,输入你的服务器ip
一切顺利的话成功进入登陆页面(不顺利应该是php扩展的原因,再调试):
8.性能调整
admin用户登陆后页面上方会有警告提示,根据提示进行更改就好...
9.PHP
vim /etc/php.ini
[PHP]
# 添加如下配置
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
upload_max_filesize = 10240M #上传大小限制
10.缓存
yum install -y memcache
vim /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="2048"
OPTIONS=""
11.nextcloud添加memcache缓存配置
vim /usr/share/nginx/html/config/config.php
'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\OC\Memcache\Memcached',
'memcached_servers' => array(
array('localhost', 11211),
),
12.重启
systemctl restart memcached
systemctl enable memcached
说明:本文完全是参照大佬的文章,边做边写,边总结,里面也有一些小提示,不喜勿喷。原文地址:https://www.jianshu.com/p/497a1f11e968 有什么问题也可以在下方留言,我们一起探讨。