Nextcloud部署私人云盤流程全記錄

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

相關文章
相關標籤/搜索