靳闯博客 记录是一种习惯,分享是一种态度
  • 波浪
  • 波浪
  • 波浪
  • 波浪
Centos7 搭建 Nextcloud个人网盘
发表于: | 分类: 技术积累 | 标签: 暂无标签 | 评论:1 | 阅读: 194

Nextcloud 官网安装文档说明

我这里的搭建环境:LNMP ;环境搭建参考:(由于是源码安装的费时间,可以参考官网安装文档安装)

Linux:centos7 最小化安装
Nginx: nginx 1.14 源码安装
Mysql: mysql 5.7 二进制包安装
Php: php 7.2 源码安装

下载程序源码

wget https://download.nextcloud.com/server/releases/nextcloud-14.0.3.zip
unzip nextcloud-14.0.3.zip
mv nextcloud /usr/local/nginx/html/
cd /usr/local/nginx/html && chown nginx.nginx nextcloud/ -R

创建数据库


[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database nextcloud default character set utf8mb4 collate utf8mb4_general_ci;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON nextcloud.* TO cloud@'127.0.0.1' IDENTIFIED BY '123456';
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

创建ssl证书

cd /usr/local/nginx/  && mkdir cert
openssl req -new -x509 -days 3650 -nodes -out /usr/local/nginx/cert/nextcloud.crt -keyout /usr/local/nginx/cert/nextcloud.key -subj "/C=CN/ST=sh/L=sh/O=jc/OU=dev/CN=jc.com/emailAddress=jc@jc.com"

#参数说明:
-new:表示生成一个新证书签署请求
-x509:专用于CA生成自签证书,如果不是自签证书则不需要此项
-key:用到的私钥文件
-out:证书的保存路径
-days:证书的有效期限,单位是day(天),默认是openssl.cnf的default_days
-subj:直接指定各个参数,不用生产时手动输入

nginx 配置文件调整

user  nginx;
worker_processes  2;
worker_rlimit_nofile 100000;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        pid/nginx.pid;

events {
    worker_connections  65532;
    multi_accept on;
    use epoll;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    fastcgi_intercept_errors on; 
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    server_tokens off; 
    sendfile        on;
    tcp_nodelay        on;    
    tcp_nopush      on;
    keepalive_timeout  65;


#uplaod_size
    client_max_body_size 2048m; 


#cache
    proxy_connect_timeout 5;
    proxy_read_timeout 60;
    proxy_send_timeout 5;
    proxy_buffer_size 16k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;
    proxy_temp_path /tmp/nginx;
    proxy_cache_path /tmp/nginx/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=500m;

    
upstream php-handler {
    server 127.0.0.1:9000;
   }


server {
    listen 80;
    server_name localhost;
    rewrite ^(.*)$ https://$host$1 permanent;
    
}

server {
    listen 443;
    server_name localhost;

    #日志
    access_log logs/cloud.access.log;
    error_log logs/cloud.error.log error;
    
    #ssl配置
        ssl on;
    ssl_certificate /usr/local/nginx/cert/nextcloud.crt;
        ssl_certificate_key /usr/local/nginx/cert/nextcloud.key;

    #gzip压缩
    gzip on;
        gzip_min_length 1k;
        gzip_buffers 16 64k;
        gzip_http_version 1.1;
        gzip_comp_level 6;
        gzip_types text/plain application/javascript text/css application/json application/font-woff application/xml;
        gzip_vary on;

    #header安全设置
    add_header Referrer-Policy "no-referrer";
        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;

    #默认首页目录
    root /usr/local/nginx/html/nextcloud/;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
 
    #这儿是为了支持日历和联系人,建议加上
    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 2048M;
    fastcgi_buffers 64 4k;

        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 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;
    }

    #js/css/图片文件的转发
    location ~ \.(?:css|js|woff|svg|gif)$ {
        try_files $uri /index.php$uri$is_args$args;
        add_header Cache-Control "public, max-age=15778463";
        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;
        access_log off;
    }
    location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
        try_files $uri /index.php$uri$is_args$args;
        access_log off;
    }

    }#server结束
    
}#http结束

访问,配置

nextcloud1.png
nextcloud2.png
nextcloud3.png
nextcloud4.png
nextcloud5.png

后台任务配置

nextcloud6.png

#使用系统的crontab 计划任务
crontab -u nginx -e
#添加一条
*/15  *  *  *  * /usr/local/php7/bin/php -f /usr/local/nginx/html/nextcloud/cron.php

对于几个错误警告需要调整下php参数

##错误警告1:
The installation of PHP appears to be incorrect, and the system environment variables cannot be accessed. The getenv ("PATH") function test returns an empty space.

#解决:
vim /usr/local/php7/etc/php-fpm.d/www.conf
#去掉这几项参数前面的;符号
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

##错误警告2:
The PHP OPcache module is not loaded. For better performance it is recommended to load it into your PHP installation.

#解决:
vim /usr/local/php7/etc/php.ini #php.ini文件所在路径
#去掉这几项前面的;符号
zend_extension= opcache  #php7.2版本开启需要加上此参数
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=200
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=1
opcache.save_comments=1


##警告错误3:配置完redis缓存,打开页面出错
Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

#解决:
3.1安装phpredis扩展模块
wget https://www.jinchuang.org/novel/lnmp/phpredis-php7.zip
unzip phpredis-php7.zip
cd phpredis-php7
/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config
make
make install

3.2然后修改php.ini
vim /usr/local/php7/etc/php.ini
#在末尾加上:
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20170718/"
extension = redis.so

商业转载请联系作者获得授权,非商业转载请注明出处,谢谢合作。


如果这篇文章帮助到了你,我感到十分荣幸!

仅有一条评论

  1. 奥兹说钱 奥兹说钱   Windows 10 x64 Edition Google Chrome 63.0.3239.132

    已学习 icon_twisted.png

或许你不想写点什么·但我依旧在这里

icon_mrgreen.pngicon_neutral.pngicon_twisted.pngicon_arrow.pngicon_eek.pngicon_smile.pngicon_confused.pngicon_cool.pngicon_evil.pngicon_biggrin.pngicon_idea.pngicon_redface.pngicon_razz.pngicon_rolleyes.pngicon_wink.pngicon_cry.pngicon_surprised.pngicon_lol.pngicon_mad.pngicon_sad.pngicon_exclaim.pngicon_question.png2018new_aini_org.png2018new_baobao_thumb.png2018new_erha_org.png2018new_kuxiao_thumb.png2018new_yun_thumb.png2018new_hufen_thumb.png2018new_gui_org.png2018new_xiaoerbuyu_org.png2018new_heixian_thumb.png2018new_wabi_thumb.png2018new_tianping_thumb.png

站点地图 网站地图
豫ICP备17003270号 | Copyright © 2018 💖 靳闯博客
Typecho🍹Sgreen
TOP