Linux搭建Nextcloud,打造属于您的专属网盘
編寫初衷
沒有人生下來天生就是會計算機的,就拿筆者來說的話,也是從Windows->Centos->Ubuntu一步一步慢慢學習,積累下來的。為了讓大家能夠更快更高效率的學習,從今天開始,我將每天深入教您1個命令,讓我們一起live and study,積少成多!
安裝方法(可供參考)
1首先查看防火墻和selinux是否關(guān)閉
getenforce
systemctl status firewalld
2安裝nginx
yum -y install nginx
3安裝php7.1
rpm -Uvh?https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh?https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum search php71w
yum install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath php-dom
4檢測是否安裝成功
#nginx -v
nginx version: nginx/1.12.2
#php -v
PHP 7.1.29 (cli) (built: May 13 2019 18:32:21) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
5使用 vim 編輯默認的 php7-fpm 配置文件。
vim /etc/php-fpm.d/www.conf
在第 8 行和第 10行,user 和 group 賦值為 nginx。
user = nginx
group = nginx
在第 22 行,確保 php-fpm 運行在指定端口。
listen = 127.0.0.1:9000
取消第 366-370 行的注釋,啟用 php-fpm 的系統(tǒng)環(huán)境變量。
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
6就是在 /var/lib/ 目錄下創(chuàng)建一個新的文件夾 session,并將其擁有者變更為 nginx 用戶。
mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/
然后啟動 php-fpm 和 Nginx,并且將它們設(shè)置為隨開機啟動的服務(wù)。
systemctl start php-fpm
systemctl start nginx?
systemctl enable php-fpm
systemctl enable nginx
7安裝mysql
我這里使用 MariaDB 作為 Nextcloud 的數(shù)據(jù)庫??梢灾苯邮褂?yum 命令從 CentOS 默認遠程倉庫中安裝 mariadb-server包。
yum -y install mariadb mariadb-server
啟動 MariaDB,并將其添加到隨系統(tǒng)啟動的服務(wù)中去。
systemctl start mariadb
systemctl enable mariadb
mysql數(shù)據(jù)庫搭建完成是沒有密碼的自己可以設(shè)置,我在這里沒有設(shè)置密碼直接登陸
直接進入數(shù)據(jù)庫創(chuàng)建名為 nextcloud_db 的數(shù)據(jù)庫以及名為 nextclouduser 的用戶,用戶密碼為 nextclouduser。當然自己也可以隨意設(shè)置密碼。
create database nextcloud_db;
create user nextclouduser@localhost identified by 'nextclouduser';
grant all privileges on nextcloud_db.* to nextclouduser@localhost identified by 'nextclouduser';
flush privileges;
8為nextcloud 生成自簽名ssl證書
為 SSL 文件創(chuàng)建新目錄:
mkdir -p /etc/nginx/cert/
使用 openssl 生成一個新的 SSL 證書。
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key
會出現(xiàn)一下信息,可以隨便填寫
Country Name (2 letter code) [XX]:cn //國家
State or Province Name (full name) []:guangdong //省份
Locality Name (eg, city) [Default City]:guangzhou //地區(qū)名字
Organization Name (eg, company) [Default Company Ltd]:Amos //公司名
Organizational Unit Name (eg, section) []:Technology //部門
Common Name (eg, your name or your server's hostname) []:Amos //CA主機名
Email Address []:Amos@Amos.com //Email地址
修改文件夾權(quán)限
chmod 600 /etc/nginx/cert/*
chmod 700 /etc/nginx/cert
9下載Nextcloud
wget?https://download.nextcloud.com/server/releases/nextcloud-13.0.1.zip
解壓
unzip nextcloud-13.0.1.zip
移動到nginx站點目錄
mv nextcloud/ /usr/share/nginx/html/
創(chuàng)建nextcloud的存儲目錄并設(shè)置權(quán)限
cd /usr/share/nginx/html/
mkdir -p nextcloud/data/
chown nginx:nginx -R nextcloud/
10編輯nginx配置文件
cd /etc/nginx/conf.d/
vim nextcloud.conf
upstream php-handler {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name wangpan.zkzd.cn;
return 301?https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name cloud.nextcloud.co;
ssl_certificate /etc/nginx/cert/nextcloud.crt;ssl_certificate_key /etc/nginx/cert/nextcloud.key;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/share/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;
}client_max_body_size 512M;fastcgi_buffers 64 4K;gzip 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;
}location ~* \.(?:css|js)$ {
????try_files $uri /index.php$uri$is_args$args;
????add_header Cache-Control "public, max-age=7200";
????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;
????access_log off;
}
location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
????try_files $uri /index.php$uri$is_args$args;
????access_log off;
}
}
檢查nginx語法正確重啟nginx
nginx -t
systemctl restart nginx
注意:中間可能有php模塊沒有安裝,自己yum安裝一下缺少的模塊不一一闡述了!
yum install php-dom
yum install php-xml --skip-broken
11登陸外面頁面看是否搭建成功,一般是用域名也可以是IP訪問,如果報錯500 看下nginx配置文件 是否正確 百分之99是配置文件錯誤,希望對大家有所幫助。
總結(jié)
以上是生活随笔為你收集整理的Linux搭建Nextcloud,打造属于您的专属网盘的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: GitHub提交出错处理【2022年】
- 下一篇: 机器学习入门要学习什么内容呢?
