Nextcloud-13.0.5部署实践记录:
1、环境说明LNMP版本信息
系统: CentOS Linux release 7.5.1804 (Core)
软件:nginx-1.12.2 mariadb-10.2.15 php7.0
-----------------------------------------------
配置163YUM源
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all
yum makecache
2、安装仓库源、redis
一、添加EPEL包的仓库源
yum install epel-release
二、添加 PHP7-FPM webtatic 仓库
rpm-Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install redis
3、安装PHP7和PHP7-FPM
yum install php70w-fpm php70w-cli php70w-gd php70w-mcrypt php70w-mysql php70w-pear \
php70w-xml php70w-mbstring php70w-pdo php70w-json php70w-pecl-apcu php70w-pecl-apcu-devel
4、配置PHP-FPM
一、咱们须要配置 php-fpm 与 Nginx 协同运行。php7-fpm将使用nginx 用户来运行,并监听 9000 端口。
编辑默认的php7-fpm配置文件。
vi /etc/php-fpm.d/www.conf
------------------------------------------------------------------------------
user = nginx //将用户和组都改成nginx
group = nginx
.....
listen = 127.0.0.1:9000 //php-fpm所监听的端口为9000
......
env[HOSTNAME] = $HOSTNAME //去掉下面几行注释366行
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
-------------------------------------------------------------------------------
二、须要在 /var/lib/ 目录下建立一个新的文件夹 session,并将其拥有者变动为 nginx 用户。
最后启动 php-fpm 和 Nginx,而且将它们设置为随开机启动的服务。
mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/ javascript
(注:若是没建nginx用户:useradd -s /sbin/nologin -M nginx)php
三、vi/etc/php.d/opcache.ini 去掉如下行注释,修改成对应的配置值:
vi/etc/php.d/opcache.ini
---------------------------------
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=1
opcache.save_comments=1
----------------------------------
注:未装opcache的请看下面
php -v #查询php版本
yum search opcache php #YUM查询并安装对应PHP版本的opcache
yum install php70w-opcache.x86_64
四、启动php-fpm 和nginx服务
systemctl start php-fpm
systemctl enable php-fpm
systemctl start redis
systemctl enable redis
chkconfig nginx on
5、配置MariaDB, 建立数据库、建立库用户、用户受权
mysql -u root -p
create database nextclouddb;
create user ncuser@'%' identified by'ncdb1234';
grant all privileges on nextclouddb.* to ncuser@'%' identified by 'ncdb1234';
flush privileges;
exit
6、安装SSL证书咱们能够本身生成SSL证书,也能够申请专业的SSL证书。
自签名的SSL证书在使用的时候会报错,建议使用有资质的SSL证书。 安装过程以下:
一、为SSL 文件建立新目录:
mkdir -p /etc/nginx/cert/
二、建立证书(生产环境请购买公网SSL证书)
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/misemcloud.crt -keyout /etc/nginx/cert/misemcloud.key
三、在该目录下储存申请过的SSL证书,并设置证书的权限:
chmod 700 /etc/nginx/cert
chmod 600 /etc/nginx/cert/*
7、初步安装 Nextcloud
一、下载解压到浏览器(apache或者nginx)
unzip nextcloud-13.0.5.zip
mv mv nextcloud /usr/local/nginx/html/
chown -R nginx:nginx /usr/local/nginx/html/
二、为NextCloud建立文件储存文件夹,并授予必定的权限
/usr/local/nginx/
mkdir /datacloud
chown -R nginx:nginx /datacloud/
8、配置Nginx转发规则
一、建立文件: (只改以下三处)
# 注意:server_name 须要改成域名
# ssl_certificate和ssl_certificate_key须要改成SSL证书对应的文件
# root 须要改成nextcloud文件夹所在路径
vi /usr/local/nginx/conf/nginx.conf
----------------------------------------------------------------------------------------
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name www.misem.top;
# enforce https
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name www.misem.top;
ssl_certificate /etc/nginx/cert/misemcloud.crt;
ssl_certificate_key /etc/nginx/cert/misemcloud.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;";
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header X-Content-Type-Options nosniff;
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;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# Path to the root of your installation
root /usr/local/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 512M;
fastcgi_buffers 64 4K;
# Enable gzip but do not remove ETag headers
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;
location / {
rewrite ^ /index.php$request_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/.+)\.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_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|woff|svg|gif)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
# 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;";
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header X-Content-Type-Options nosniff;
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 ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$request_uri;
# Optional: Don't log access to other assets
access_log off;
}
}
}
--------------------------------------------------------------------------------------------------
#附:官方配置文档 https://docs.nextcloud.com/server/13/admin_manual/installation/nginx.html
九,网页安装Nextcloud
vi /etc/hosts
139.159.182.198 www.misem.top
#在台式机HOSTS也加本地域名
浏览器输入https://139.159.182.198/nextcloudcss
nextcloud必定要改成nginx所属,有时不注意就会报错html
数据库主机:139.159.182.198:5945 (查看实际端口号)
GRANT ALL PRIVILEGES ON *.* TO 'ncuser'@'139.159.182.198' IDENTIFIED BY 'ncdb1234' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'ncuser'@'%' IDENTIFIED BY 'ncdb1234' WITH GRANT OPTION;
第一次没有反应,
从新运行第二次能够了java
重要,重要,重要:node
关闭selinux和防火墙
# vi /etc/selinux/config
//SELINUX=enforcing改成SELINUX=disabled mysql
十:一些优化设置:
1 . HTTP 请求头“Strict-Transport-Security”没有配置为至少“15552000”秒,出于加强安全性考虑,
咱们推荐按照安全提示中的说明启用HSTS
---------------------------------------------
vim /application/nginx/conf/nginx.conf
#在server {
listen 443 ssl;
#下面加入一行:
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
----------------------------------------------------------------------------------------------------------------
二、内存缓存未配置. 若是可用, 请配置 memcache 以加强性能. 更多信息请查看咱们的…
nextcloud支持内存加速,它可支持3种方式APCu,Memcached,Redis。这里只展现APCu的配置
安装apcu
yum search apcu php
yum install 文件名(对应php版本)
vim /application/nginx/html/nextcloud/config/config.php
如下内容加入倒数第二行
'memcache.local' => '\\OC\\Memcache\\APCu',
----------------------------------------------------------------------------------------------------------------
结束语:
至此,一台私有云盘搭建完毕,欢迎交流指正。
linux