八、树莓派LNMP安装nextcloud云盘详细教程

八、树莓派安装nextcloud,部署自己的云盘

使用树莓派部署一个自己的云盘,来完成一些手机,电脑间的文件操作,同时,摒弃百度云盘的限速。由于是树莓派,不推荐LAMP方式,这里我们用LNMP方式。

基于LNMP安装。

先安装Nginx,php-fpm,MySQL。这些安装都比较简单,mysql对应是mariadb-server。
直接sudo apt-get install 就好。
我前面的文章里也有mysql 的安装,可以翻开看,下面详细步骤都会说到。
这个参考可以见LNMP官方
安装时需要注意一点,nextcloud要求php版本必要php7.0及以上
我这里用的是7.3。

更新并安装必要软件

更新系统并安装必要软件:

sudo apt update && sudo apt upgrade && sudo apt install -y libreoffice ffmpeg
sudo apt install -y nginx
sudo apt install -y redis
sudo apt install -y php7.3 php7.3-fpm php7.3-curl php7.3-gd php7.3-dom php7.3-iconv php7.3-openssl php-redis php-mysql php7.3-zip php7.3-bz2 php7.3-intl php7.3-imagick

下载准备安装包文件

准备好了后,去官网下载安装包
然后拷贝到树莓派上,可以使用FileZilla这个软件传输。
或者:
wget https://download.nextcloud.com/server/releases/nextcloud-18.0.4.zip
解压并移动到/var/www/html内

unzip nextcloud-18.0.4.zip
sudo mv nextcloud /var/www/html

到对应目录下
cd /var/www/html
更改权限
sudo chown -R root:root nextcloud
创建data 数据文件夹
cd nextcloud; sudo mkdir data
更改子文件夹权限
sudo chown -R www-data:www-data data config apps

准备对应的数据库

安装mysql,并新建一个数据库,配置好用户和权限,
具体可参考我的这篇,里面有详细的mysql安装树莓派安装gitea

挂接移动硬盘

接一个外接移动硬盘,挂载到树莓派上,具体参考我的树莓派挂载硬盘
挂载后就可以访问硬盘,新建nextcloud文件夹。后面配置用得到。

配置

配置php:

编辑/etc/php/7.3/fpm/php.ini文件,做如下更改:
sudo nano /etc/php/7.3/fpm/php.ini

  • expose_php改成off
  • date.timezone 这里删掉前面的;号,值改成Asia/Shanghai
  • 删掉opcache.enable=1,opcache.validate_timestamps=1,opcache.revalidate_freq=2这三行前面的;号,将opcache.revalidate_freq的值改成30;

配置nginx

在/etc/nginx/sites-enabled目录下,创建一个nextcloud文件并编辑:
sudo nano /etc/nginx/sites-enabled/nextcloud

  • 这里端口自己设置,
  • server_name 自己设置,自己的域名。
  • ssl不启用的话,就关掉。
  • 其他的看着设置把,基本都不用动,这个是我已经运行的。
upstream php-handler {
server unix:/run/php/php7.3-fpm.sock;
}

server {
listen 80;
listen [::]:80;
server_name www.nextcloud.com;

# Path to the root of your installation
root /var/www/html/nextcloud;

ssl on;
ssl_certificate /etc/nginx/nextcloud_SSL/server.pem;
ssl_certificate_key /etc/nginx/nextcloud_SSL/server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security max-age=15768000;


#(可选)添加如下header主要为了安全
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
#(可选)为了支持user_webfinger 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 = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
    try_files $uri $uri/ =404;
}

 #这儿是为了支持日历和联系人,建议加上
location = /.well-known/carddav {
  return 301 $scheme://$host:$server_port/remote.php/dav;
}
#设置上传文件的最大大小(还和php里的那个设置有关)
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 128K;
send_timeout 60;

# 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$

# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;

location / {
    rewrite ^ /index.php;
}
 #安全设置,禁止访问部分敏感内容
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\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
    fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
    set $path_info $fastcgi_path_info;
    try_files $fastcgi_script_name =404;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $path_info;
    #fastcgi_param HTTPS on;
    # Avoid sending the security headers twice
    fastcgi_param modHeadersAvailable true;
    # Enable pretty urls
    fastcgi_param front_controller_active true;
    fastcgi_pass php-handler;
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
}
#安全设置,禁止访问部分敏感内容
location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
    try_files $uri/ =404;
    index index.php;
}

# Adding the cache control header for js, css and map files
# Make sure it is BELOW the PHP block
location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
    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;" always;
    #
    # 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 Referrer-Policy "no-referrer" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-Download-Options "noopen" always;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Permitted-Cross-Domain-Policies "none" always;
    add_header X-Robots-Tag "none" always;
    add_header X-XSS-Protection "1; mode=block" always;

    # Optional: Don't log access to assets
    access_log off;
}

location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
    try_files $uri /index.php$request_uri;
    # Optional: Don't log access to other assets
    access_log off;
}
}

重启nginx:
sudo nginx -s reload

配置nextcloud

前面配置好后,就可以了访问了:
本地ip:http://192.168.1.2:8080
将出现nextcloud的设置页面,设置数据目录,这里就要用到移动硬盘:
/home/pi/mobiledisk/nextcloud
选择用户名和密码,以及输入数据库用户名和密码,完成设置。
这里如果报错文件权限问题;
可以打开配置文件,并修改配置:
sudo nano /var/www/html/nextcloud/config/config.php
'check_data_directory_permissions' => false,

配置 redis

sudo nano /var/www/html/nextcloud/config/config.php

'memcache.locking' => '\OC\Memcache\Redis',
  'memcache.distributed' => '\OC\Memcache\Redis',
  'redis' => [
     'host' => '127.0.0.1',
     'port' => 6379,
   ],

配置APPs

去官网下载需要的app,对应自己的版本,
nextcloud APPs

下载后,解压并上传到/var/www/html/nextcloud/apps下。就可以在设置里使用了。

部署Collabora Office

使用docker安装,由于不支持arm-32架构,这里就不详细叙述了。

docker运行

docker run -t -d -p 127.0.0.1:9980:9980 -e 'domain=docs\\.thingslink\\.top' -e "username=admin" -e "password=123456" --restart always --cap-add MKNOD collabora/code
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值