1. 程式人生 > >centos7部署Nextcloud私人網盤

centos7部署Nextcloud私人網盤

環境:

centos版本 CentOS Linux release 7.5.1804 (Core) 
核心版本 3.10.0-862.el7.x86_64
資料庫 MySQL5.7
Nextcloud nextcloud-13.0.0
PHP PHP 7

1、安裝基本工具關閉防火牆,或者開放埠。都行

[[email protected] ~]# yum -y install epel-release wget unzip gcc

[
[email protected]
~]# yum -y install libsmbclient libsmbclient-devel redis [[email protected] ~]# setenforce 0 [[email protected] ~]# systemctl stop firewalld

2、安裝MySQL,redis

[[email protected] ~]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm

[[email protected]
~]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm [[email protected] ~]# yum install mysql-server -y [[email protected] ~]# systemctl start mysqld 這裡去mysqld.log拿到密碼,修改原始密碼 [[email protected] ~]# mysqladmin -uroot -p'91d7g+o*ZivG' password 'YingYingYing!111' 進入資料庫授權 mysql> create database nextcloud_db; mysql> create user
[email protected]
identified by 'YingYingYing!111'; mysql> grant all privileges on nextcloud_db.* to [email protected] identified by 'YingYingYing!111'; mysql> flush privileges;

3、安裝nginx,redis

[[email protected] ~]# yum -y install nginx

[[email protected] ~]# mkdir /var/www

[[email protected] ~]# chown -R nginx:nginx /var/www

啟動nginx
[[email protected] ~]# systemctl start nginx

[[email protected] ~]# yum -y install redis

redis這裡有點懵逼,可以先不安裝或者安裝不修改任何配置,服務一樣可以起來

4、安裝PHP

[[email protected] ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

[[email protected] ~]# yum -y install php71w-fpm php71w-cli php71w-gd php71w-mcrypt php71w-mysql php71w-pear php71w-xml php71w-mbstring php71w-pdo php71w-json php71w-opcache php71w-pecl-apcu php71w-pecl-apcu-devel php71w-pecl-igbinary php71w-pecl-igbinary-devel php71w-pecl-imagick php71w-pecl-imagick-devel php71w-pecl-redis php71w-pecl-redis-devel

修改配置檔案
[[email protected] ~]# vim /etc/php-fpm.d/www.conf
apache改為nginx
user = nginx
group = nginx
註釋解開
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

[[email protected] ~]# mkdir -p /var/lib/php/session 

[[email protected] ~]# chown -R nginx:nginx /var/lib/php/session/

[[email protected] ~]# vim /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

安裝smbclient模板

[[email protected] ~]# yum -y install libsmbclient libsmbclient-devel

[[email protected] ~]# pecl install smbclient

[[email protected] ~]# vim /etc/php.d/smbclient.ini     //新增下面這一行
extension=smbclient.so

啟動PHP-fpm服務

[[email protected] ~]# systemctl start php-fpm

五、安裝Nextcloud

5.1、下載並解壓到www目錄
[[email protected] ~]# wget https://download.nextcloud.com/server/releases/nextcloud-13.0.0.zip

[[email protected] ~]# unzip nextcloud-13.0.0.zip 

[[email protected] ~]# mv nextcloud /var/www/

[[email protected] ~]# chown -R nginx:nginx /var/www

5.2、生成SSL證書
[[email protected] ~]# mkdir -p /etc/nginx/cert/

[[email protected] ~]# openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key

[[email protected] ~]# chmod 700 /etc/nginx/cert

[[email protected] ~]# chmod 600 /etc/nginx/cert/*

5.3、在Nginx配置
老多了   往下看直接粘上去就行
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  logs/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.suibianxie.com;
        # enforce https
        return 301 https://$server_name$request_uri;
    }

    server {
        listen 443 ssl http2;
        server_name www.suibianxie.com;

        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;";
        #
        # 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;

        # Path to the root of your installation
        root /var/www/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$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$uri$is_args$args;
            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$uri$is_args$args;
            # Optional: Don't log access to other assets
            access_log off;
        }
    }

}

[[email protected] ~]# nginx -t   //檢視配置是否錯誤,無錯的話  重啟nginx,或者直接nginx重新載入配置

[[email protected] ~]# nginx -s reload
或
[[email protected] ~]# systemctl restart nginx




解析過後,訪問  www.suibianxie.com 就可以  賬號密碼自行設定