- Forever Young https://www.luxiyue.com/tag/nextcloud/ Share Happiness,Enjoy Life~ Thu, 06 Apr 2023 08:40:29 +0000 zh-Hans hourly 1 https://wordpress.org/?v=6.8.3 https://www.luxiyue.com/wp-content/uploads/cropped-lovely-ina512-1-1-150x150.png - Forever Young https://www.luxiyue.com/tag/nextcloud/ 32 32 解决nextcloud错误提示 Could not connect to appstore-cURL error 28 https://www.luxiyue.com/server/%e8%a7%a3%e5%86%b3nextcloud%e9%94%99%e8%af%af%e6%8f%90%e7%a4%ba/ https://www.luxiyue.com/server/%e8%a7%a3%e5%86%b3nextcloud%e9%94%99%e8%af%af%e6%8f%90%e7%a4%ba/#respond Tue, 07 Mar 2023 09:38:18 +0000 https://www.luxiyue.com/?p=4350 前言 在使用nextcloud的过程中,后台日志总会出现警告: Could not connect to appstore: cURL error 28: Operation timed out after 60000 milliseconds with 1191922 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-error […]

解决nextcloud错误提示 Could not connect to appstore-cURL error 28最先出现在Forever Young

]]>
前言

在使用nextcloud的过程中,后台日志总会出现警告:

Could not connect to appstore: cURL error 28: Operation timed out after 60000 milliseconds with 1191922 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://apps.nextcloud.com/api/v1/apps.json

虽然这个警告是因为nextcloud的API无法访问,是一个常见的问题,无伤大雅,不影响使用。

但是看着有点心烦,索性通过以下方法把它去掉。

方法

  1. 打开nextcloud的文件夹,找到如下文件:/path/to/nextcloud/lib/private/Installer.php

  2. 查找 $timeout = $this->isCLI ? 0 : 120; 这一行

    // Download the release
    $tempFile = $this->tempManager->getTemporaryFile('.tar.gz');
    $timeout = $this->isCLI ? 0 : 120;
    $client = $this->clientService->newClient();
    $client->get($app['releases'][0]['download'], ['sink' => $tempFile, 'timeout' => $timeout]);
  3. 120 这个数值调大,或者直接注释掉这行

最后

当然,建议还是将这个数值调大,改成 300 或者 500 给服务器充分的连接时间,如果直接注释掉可能会导致服务器始终在尝试连接,从而影响服务器性能。

因为这是老问题,好几年了,这个方法也是治标不治本。

解决nextcloud错误提示 Could not connect to appstore-cURL error 28最先出现在Forever Young

]]>
https://www.luxiyue.com/server/%e8%a7%a3%e5%86%b3nextcloud%e9%94%99%e8%af%af%e6%8f%90%e7%a4%ba/feed/ 0
Nginx服务配置篇·第五课:为Nextcloud配置安装onlyoffice保姆级教程 https://www.luxiyue.com/server/nginx%e6%9c%8d%e5%8a%a1%e9%85%8d%e7%bd%ae%e7%af%87%c2%b7%e7%ac%ac%e4%ba%94%e8%af%be%ef%bc%9a%e4%b8%banextcloud%e9%85%8d%e7%bd%ae%e5%ae%89%e8%a3%85onlyoffice%e4%bf%9d%e5%a7%86%e7%ba%a7%e6%95%99/ https://www.luxiyue.com/server/nginx%e6%9c%8d%e5%8a%a1%e9%85%8d%e7%bd%ae%e7%af%87%c2%b7%e7%ac%ac%e4%ba%94%e8%af%be%ef%bc%9a%e4%b8%banextcloud%e9%85%8d%e7%bd%ae%e5%ae%89%e8%a3%85onlyoffice%e4%bf%9d%e5%a7%86%e7%ba%a7%e6%95%99/#respond Thu, 29 Sep 2022 03:57:37 +0000 https://www.luxiyue.com/?p=101 结论放在开头 一、如果想装免费的社区版本,没必要。(另外两个收费版本的不知道,毕竟不是刚需,就不花这个额外的钱了) 稍微体验了几分钟,缺点如下: 卡死在打开界面 免费的社区版不支持在线编辑 自带的 NextcloudOffice 已经支持在线编辑功能 二、想学技术的话,这篇文章没有啥技术可言(其实也有,至少我搜遍百度和google都没查到什么有用的东西,这可能是全网第一篇),只保证按照步骤来可以配 […]

Nginx服务配置篇·第五课:为Nextcloud配置安装onlyoffice保姆级教程最先出现在Forever Young

]]>
结论放在开头

一、如果想装免费的社区版本,没必要。(另外两个收费版本的不知道,毕竟不是刚需,就不花这个额外的钱了)
稍微体验了几分钟,缺点如下:

  1. 卡死在打开界面

  2. 免费的社区版不支持在线编辑

  3. 自带的 NextcloudOffice 已经支持在线编辑功能

二、想学技术的话,这篇文章没有啥技术可言(其实也有,至少我搜遍百度和google都没查到什么有用的东西,这可能是全网第一篇),只保证按照步骤来可以配置成功

三、如果你耐心看完,可以学到一些处理问题的方法,写这篇文章的核心也在这,不然深夜写这个还是有点拉高我的血压的,折腾几个小时发现体验不是很好。

环境基础

  1. Ubuntu20.04

  2. Nginx

  3. 网上80%的教程都是基于Docker的,我不想用

操作步骤

第一部分:安装OnlyOffice Document Server

抄作业环节,一共就10条左右命令,照抄完事,当然可以更改的地方我注释了。也可以看官方文档,一样的。

命令的意思不写了,这个网上自己查吧。

命令1:

curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash -
sudo apt-get install -y nodejs

命令2:

apt install libcurl4 libxml2 supervisor fonts-dejavu fonts-liberation ttf-mscorefonts-installer fonts-crosextra-carlito fonts-takao-gothic fonts-opensymbol

这里就不得不说官方安装指导里面还是libcurl3,都libcurl4了。

命令3:

apt install postgresql

命令4:

sudo -i -u postgres psql -c "CREATE DATABASE onlyoffice;"
sudo -i -u postgres psql -c "CREATE USER onlyoffice WITH password 'onlyoffice';"     #后面那个onlyoffice是密码,你自己可以设置
sudo -i -u postgres psql -c "GRANT ALL privileges ON DATABASE onlyoffice TO onlyoffice;"

命令5:

sudo apt-get install rabbitmq-server

命令6:

sudo apt-get install nginx-extras

命令7:

echo onlyoffice-documentserver onlyoffice/ds-port select | sudo debconf-set-selections  # 换成你想用的端口号

这是最大的坑,让我浪费了好几个小时

命令8:

mkdir -p ~/.gnupg
chmod 700 ~/.gnupg
gpg --no-default-keyring --keyring gnupg-ring:/tmp/onlyoffice.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys CB2DE8E5
chmod 644 /tmp/onlyoffice.gpg
sudo chown root:root /tmp/onlyoffice.gpg
sudo mv /tmp/onlyoffice.gpg /etc/apt/trusted.gpg.d/

命令9:

echo "deb https://download.onlyoffice.com/repo/debian squeeze main" | sudo tee /etc/apt/sources.list.d/onlyoffice.list

命令10:

sudo apt-get update

命令11:

sudo apt-get install onlyoffice-documentserver

一般这一步不会出错,我是软件库版本太新需要根据情况下面2选1进行安装:

apt install mysql-client
apt install mariadb-client

第二部分:过程中出现的问题

1.端口的问题

根据官方指导,如果不改端口会造成端口冲突导致无法访问。

因此我把端口号改了,比如 9000 ,这样访问就变成了 域名:端口 ,但是不知道是什么原因,改了好几个端口,就是访问不了。

现在想起来可能当时配置文件有点问题,用了其他办法解决问题后再回过头来看这个问题就很简单了。不多细说了。

一顿操作下来,恍然大悟,自己真蠢,端口冲突主要是针对Apache和Nginx两个的,我就一个Nginx不用改!就默认 80443

2.https的问题

这一块网上没有教程,全靠自己摸索。

让我回过头去思考问题的出发点是,因为它是基于Nginx的,先研究它的配置文件,研究下来大体和常规网站配置差不多。

Holy shit,都什么年代了,ssl默认配置文件中居然还有 ssl on; 的参数,下面倒是有 ssl certificate 填SSL证书的地方,但是还是不对,没有 server name 栏,不然怎么和证书关联起来呢(因为它默认就是IP/域名,也就是你的主页 a.com 这个,因为我域名已经配置给博客了,所以要改成其他子域名)

其实这两个问题,我写出来很简单,但是在实际操作过程中,每一步验证都需要花费很多时间,一行行代码逐个对,如果只是根据它的默认配置文件来改,不去追溯基础原理思考分析问题出现在哪,估计真的卡死在这里了。

第三部分:配置细节

程序目录:/etc/onlyoffice/

配置文件:

软链接:/etc/nginx/conf.d/ds.conf

真实路径为:/etc/onlyoffice/documentserver/nginx/ds.conf

直接说详细步骤吧:

1.准备子域名+证书

自签好像也可以,这里不研究了

比如子域名为:z.a.com

2.修改配置文件

/etc/onlyoffice/documentserver/nginx/ds.conf 只有 http listen 80 的配置参数

/etc/onlyoffice/documentserver/nginx/ 下面有个 ds-ssl.conf.tmpl 文件,这个是完整的配置文件

直接把 ds.conf 删除

rm /etc/onlyoffice/documentserver/nginx/ds.conf

拷贝 ds-ssl.conf.tmpl 并重命名为 ds.conf

cp /etc/onlyoffice/documentserver/nginx/ds-ssl.conf.tmpl /etc/onlyoffice/documentserver/nginx/ds.conf

修改 ds.conf 配置

vim /etc/onlyoffice/documentserver/nginx/ds.conf

下面为配置参数:

include /etc/nginx/includes/http-common.conf;

## Normal HTTP host
server {
        listen 80;
        listen [::]:80;
  server_name z.a.com;   #更改为你的子域名
  server_tokens off;

### Redirects all traffic to the HTTPS host
  root /nowhere; ## root doesn't have to be a valid path since we are redirecting
  rewrite ^ https://$host$request_uri? permanent;
}

#下面几个都注释掉
#HTTP host for internal services
#server {
#  listen 127.0.0.1:80;
#  listen [::1]:80;
#  server_name localhost;
#  server_tokens off;

#  include /etc/nginx/includes/ds-common.conf;
#  include /etc/nginx/includes/ds-docservice.conf;
#}

server {
  listen [::]:443 ssl http2;
  server_tokens off;
  root /usr/share/nginx/html;
  server_name z.a.com;   #更改为你的子域名

  ## Strong SSL Security
  ## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html

  ssl_certificate /etc/xxxx.pem;   #更改为你的子域名证书路径
  ssl_certificate_key /etc/xxx.key;   #更改为你的子域名证书路径
  # Uncomment string below and specify the path to the file with the password if you use encrypted certificate key
  # ssl_password_file {{SSL_PASSWORD_PATH}};
  ssl_verify_client off;

  ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";

  ssl_protocols TLSv1.2;
  ssl_session_cache  builtin:1000  shared:SSL:10m;

  ssl_prefer_server_ciphers   on;

  add_header Strict-Transport-Security max-age=31536000;
  # add_header X-Frame-Options SAMEORIGIN;
  add_header X-Content-Type-Options nosniff;

  ## [Optional] If your certficate has OCSP, enable OCSP stapling to reduce the overhead and latency of running SSL.
  ## Replace with your ssl_trusted_certificate. For more info see:
  ## - https://medium.com/devops-programming/4445f4862461
  ## - https://www.ruby-forum.com/topic/4419319
  ## - https://www.digitalocean.com/community/tutorials/how-to-configure-ocsp-stapling-on-apache-and-nginx
  # ssl_stapling on;
  # ssl_stapling_verify on;
  # ssl_trusted_certificate /etc/nginx/ssl/stapling.trusted.crt;
  # resolver 208.67.222.222 208.67.222.220 valid=300s; # Can change to your DNS resolver if desired
  # resolver_timeout 10s;

  ## [Optional] Generate a stronger DHE parameter:
  ##   cd /etc/ssl/certs
  ##   sudo openssl dhparam -out dhparam.pem 4096
  ##
  # ssl_dhparam /etc/ssl/certs/dhparam.pem;

  include /etc/nginx/includes/ds-*.conf;

}

直接保存退出即可。

3.重启Nginx并验证

systemctl restart nginx

打开配置的域名,显示以下页面就成功了。

页面里面那个 Test Example 不要做,做了的话,别人有这个网址也可以进去体验操作文档,我没研究怎么关掉这个。

4.配置Nextcloud

打开Nextcloud仪表盘,右上角 头像 - 应用 (如果没有应用的,自己查资料吧,好像可以换成国内应用商店的)- Office&Text ,找到 OnlyOffice ,点击 下载并启用

再点击 头像 - 设置 ,左侧会有 ONLYOFFICE 的选项,点进去。

ONLYOFFICE Docs地址栏 输入你配置好的域名,比如 https://z.a.com/ ,密钥为空 ,点击保存后如果成功了,下面会显示常用设置选项。

至此,为NextCloud配置ONLYOFFICE已经是配置完成了。

最后就不吐槽了,毕竟免费的它不香也很正常。

Nginx服务配置篇·第五课:为Nextcloud配置安装onlyoffice保姆级教程最先出现在Forever Young

]]>
https://www.luxiyue.com/server/nginx%e6%9c%8d%e5%8a%a1%e9%85%8d%e7%bd%ae%e7%af%87%c2%b7%e7%ac%ac%e4%ba%94%e8%af%be%ef%bc%9a%e4%b8%banextcloud%e9%85%8d%e7%bd%ae%e5%ae%89%e8%a3%85onlyoffice%e4%bf%9d%e5%a7%86%e7%ba%a7%e6%95%99/feed/ 0
Nginx服务配置篇·第四课:NextCloud优化整合 https://www.luxiyue.com/server/nginx%e6%9c%8d%e5%8a%a1%e9%85%8d%e7%bd%ae%e7%af%87%c2%b7%e7%ac%ac%e5%9b%9b%e8%af%be%ef%bc%9anextcloud%e4%bc%98%e5%8c%96%e6%95%b4%e5%90%88/ https://www.luxiyue.com/server/nginx%e6%9c%8d%e5%8a%a1%e9%85%8d%e7%bd%ae%e7%af%87%c2%b7%e7%ac%ac%e5%9b%9b%e8%af%be%ef%bc%9anextcloud%e4%bc%98%e5%8c%96%e6%95%b4%e5%90%88/#respond Wed, 28 Sep 2022 03:53:52 +0000 https://www.luxiyue.com/?p=99 前景概要 上一篇文章我们安装完Nextcloud,打造了你的第一个私人网盘,但是会发现在设置-概览页面,依然会有一些设置上的警告。 这篇文章会一个一个进行处理,达到所有检查都通过并针对性地优化服务器。 安全与警告界面 1.缓存 推荐 Redis apt install redis 修改 config.php 配置文件: vim /var/www/nextcloud/config/config.ph […]

Nginx服务配置篇·第四课:NextCloud优化整合最先出现在Forever Young

]]>
前景概要

上一篇文章我们安装完Nextcloud,打造了你的第一个私人网盘,但是会发现在设置-概览页面,依然会有一些设置上的警告。

这篇文章会一个一个进行处理,达到所有检查都通过并针对性地优化服务器。

安全与警告界面

1.缓存

推荐 Redis

apt install redis

修改 config.php 配置文件:

vim /var/www/nextcloud/config/config.php

在最后 ) 前加入:

#开启缓存,分类型同时使用APCU和REDIS。
'memcache.local' => '\\OC\\Memcache\\APCu',
'filelocking.enabled' => true,
'memcache.locking' => '\OC\Memcache\Redis',
'memcache.distributed' => '\OC\Memcache\Redis',
'redis' => [
    'host' => 'localhost',
    'port' => 6379,
],

2.PHP的 memory_limit 以及 opcache.memory_consumption 优化

由于之前安装完PHP没有进行优化,类似上传文件大小等,这边全部贴上,避免来回编辑:

vim /etc/php/8.1/fpm/php.ini

依次搜索下面几项并更改其内容:

php_value max_input_time 3000
php_value max_execution_time 6000
memory_limit = 1024M
post_max_size = 1024M
upload_max_filesize = 1024M
max_file_uploads = 100
opcache.enable = 1
opcache.interned_strings_buffer = 32
opcache.max_accelerated_files = 10000
opcache.memory_consumption = 128
opcache.save_comments = 1
opcache.revalidate_freq = 1

编辑 www.conf ,根据服务器内存配置情况填写以下数值(4G内存计算):

vim /etc/php/8.1/fpm/pool.d/www.conf

修改以下参数:

pm = dynamic
pm.max_children = 300
pm.start_servers = 18
pm.min_spare_servers = 6
pm.max_spare_servers = 36

3.默认电话区域

修改 config.php 配置文件:

vim /var/www/nextcloud/config/config.php

添加:

'default_phone_region' => 'CN',

4.增加视频预览

安装 php-imagick 以及 ffmpeg

apt install libmagickcore-6.q16-6-extra
apt install ffmpeg

修改 config.php 配置文件:

vim /var/www/nextcloud/config/config.php

添加:

'enabledPreviewProviders' =>
array (
    0 => 'OC\\Preview\\PNG',
    1 => 'OC\\Preview\\JPEG',
    2 => 'OC\\Preview\\GIF',
    3 => 'OC\\Preview\\HEIC',
    4 => 'OC\\Preview\\BMP',
    5 => 'OC\\Preview\\XBitmap',
    6 => 'OC\\Preview\\MP3',
    7 => 'OC\\Preview\\TXT',
    8 => 'OC\\Preview\\MarkDown',
    9 => 'OC\\Preview\\Movie'
),

5.更改访问国内市场

还是在 config.php 配置文件中增加:

'updater.release.channel' => 'stable',
'appstoreenabled' => true,
'appstoreurl' => 'Nextcloud',

优化

优化这块因服务器而异,这里把一些最基础的发出来供参考:

1.解除nextcloud上传文件块大小限制

进入nextcloud文件目录

cd /var/www/nextcloud

输入以下代码:

-u www-data php occ config:app:set files max_chunk_size --value 0

显示以下内容表示成功:

Config value max_chunk_size for app files set to 0

2.数据库优化

编辑 20-mysqli.ini 文件:

vim /etc/php/8.1/fpm/conf.d/20-mysqli.ini

最底下加入以下内容:

[mysql]
mysql.allow_local_infile=On
mysql.allow_persistent=On
mysql.cache_size=2000
mysql.max_persistent=-1
mysql.max_links=-1
mysql.default_port=
mysql.default_socket=/run/mysqld/mysqld.sock #这个根据我们之前的配置
mysql.default_host=
mysql.default_user=
mysql.default_password=
mysql.connect_timeout=60
mysql.trace_mode=Off

编辑 mariadb.cnf 文件:

vim /etc/mysql/mariadb.cnf

加入以下内容:

[server]
skip_name_resolve = 1
innodb_buffer_pool_size = 128M
innodb_buffer_pool_instances = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_max_dirty_pages_pct = 90
query_cache_type = 1
query_cache_limit = 2M
query_cache_min_res_unit = 2k
query_cache_size = 64M
tmp_table_size= 64M
max_heap_table_size= 64M
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1
[mysqld]
character_set_server = utf8mb4
collation_server = utf8mb4_general_ci
transaction_isolation = READ-COMMITTED
binlog_format = ROW
innodb_large_prefix=on
innodb_file_format=barracuda
innodb_file_per_table=1

3.为nextcloud启用Cron代替ajax,提高性能

方法一

添加 crontab 定时任务

crontab -u www-data -e

添加一行,并保存:

*/5 * * * * php -f /var/www/nextcloud/cron.php //每5分钟运行一次

检查效果:

crontab -u www-data -l

输出:

[snip]*/5 * * * * php -f /var/www/nextcloud/cron.php

方法二

/etc/systemd/system 目录新建 nextcloudcron.servicenextcloudcron.timer 两个文件:

vim /etc/systemd/system/nextcloudcron.service

输入以下内容:

[Unit]
Description=Nextcloud cron.php job

[Service]
User=www-data   #运行用户,一般为www-data
ExecStart=/usr/bin/php -f /var/www/nextcloud/cron.php   #你的cron.php路径,前面那个路径一般不用改,除非你是用宝塔面板之类的

[Install]
WantedBy=basic.target

保存。

vim /etc/systemd/system/nextcloudcron.timer

输入以下内容:

[Unit]
Description=Run Nextcloud cron.php every 5 minutes

[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
Unit=nextcloudcron.service

[Install]
WantedBy=timers.target

这里不用修改,就是个定时。

最后,执行下面的命令就可以了:

systemctl enable --now nextcloudcron.timer

最后点到基本设置里,选择cron的方式,等5分钟看看情况就行了。

cron运行出错解决

出错类型为在nextcloud设置-概览中看到:系统计划任务超过X小时未运行,请查看....

日志错误:OC\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache
解决方法:
修改/etc/php/8.1/mods-available/apcu.ini

vim /etc/php/8.1/mods-available/apcu.ini

添加一行:

apc.enable_cli=1

保存退出,等5分钟再看看。

当然,也可以直接在 etc/php/8.1/fpm/php.ini 中设置 opcache.enable_cli=1

总结

至此,我们已经从零开始部署了Wordpress以及Nextcloud,相信有这两个,80%的需求应该已经完成了。

如果能够成功地看完并付诸实践,相信搭建一些前端的小应用也难不倒你了。

接下来可以更加愉快的找点新东西学习学习了。

Nginx服务配置篇·第四课:NextCloud优化整合最先出现在Forever Young

]]>
https://www.luxiyue.com/server/nginx%e6%9c%8d%e5%8a%a1%e9%85%8d%e7%bd%ae%e7%af%87%c2%b7%e7%ac%ac%e5%9b%9b%e8%af%be%ef%bc%9anextcloud%e4%bc%98%e5%8c%96%e6%95%b4%e5%90%88/feed/ 0
Nginx服务配置篇·第三课:NextCloud部署安装 https://www.luxiyue.com/server/nginx%e6%9c%8d%e5%8a%a1%e9%85%8d%e7%bd%ae%e7%af%87%c2%b7%e7%ac%ac%e4%b8%89%e8%af%be%ef%bc%9anextcloud%e9%83%a8%e7%bd%b2%e5%ae%89%e8%a3%85/ https://www.luxiyue.com/server/nginx%e6%9c%8d%e5%8a%a1%e9%85%8d%e7%bd%ae%e7%af%87%c2%b7%e7%ac%ac%e4%b8%89%e8%af%be%ef%bc%9anextcloud%e9%83%a8%e7%bd%b2%e5%ae%89%e8%a3%85/#respond Tue, 27 Sep 2022 03:52:05 +0000 https://www.luxiyue.com/?p=97 前景概要: 上一篇文章我们安装完Wordpress,基本上也就知道一个简单的网站的发布流程,这一篇就开始部署Nextcloud,打造你的第一个私人网盘。 为什么推荐Nextcloud? 免费 部署简单 功能齐全,网页以及app都完美支持 Nextcloud安装最难的点就是网站配置,如果没有根据官网的配置文件的话,就可能会有如下问题: 安装时报错,导致连接不上数据库,无法访问页面 即使安装完,在 设 […]

Nginx服务配置篇·第三课:NextCloud部署安装最先出现在Forever Young

]]>
前景概要:

上一篇文章我们安装完Wordpress,基本上也就知道一个简单的网站的发布流程,这一篇就开始部署Nextcloud,打造你的第一个私人网盘。

为什么推荐Nextcloud?

  1. 免费

  2. 部署简单

  3. 功能齐全,网页以及app都完美支持


Nextcloud安装最难的点就是网站配置,如果没有根据官网的配置文件的话,就可能会有如下问题:

  1. 安装时报错,导致连接不上数据库,无法访问页面

  2. 即使安装完,在 设置 - 概览 界面,出现很多条警告

开始部署

第一步:上传Nextcloud程序到网站目录

这边以 /var/www/nextcloud 目录为例

方法1:本地下载后通过SSH软件上传到服务器

方法2:直接使用命令

wget https://download.nextcloud.com/server/releases/latest.zip
mv latest.zip /var/www
cd /var/www
unzip latest.zip

添加访问权限:

chown -R www-data:www-data /var/www/nextcloud
chmod -R 755 /var/www/nextcloud

第二步:网站配置

这边把它的登录入口定义为: cloud.example.com

有些环境需要在 fpm/php.ini (比如php8.1的路径为:/etc/php/8.1/fpm/php.ini )配置文件中修改pathinfo:(大多数情况不需要)

;cgi.fix_pathinfo = 1    #去掉注释

直接在 /etc/nginx/sites-enable/ 目录下新建一个 nextcloud.conf 的配置文件:

vim /etc/nginx/sites-enable/nextcloud.conf

贴入以下官方文档给出的配置文件:

upstream php-handler {
    server 127.0.0.1:9000;
    #server unix:/var/run/php/php7.4-fpm.sock;
}

# Set the `immutable` cache control options only for assets with a cache busting `v` argument
map $arg_v $asset_immutable {
    "" "";
    default "immutable";
}

server {
    listen 80;
    listen [::]:80;
    server_name cloud.example.com;

    # Prevent nginx HTTP Server Detection
    server_tokens off;

    # Enforce HTTPS
    return 301 https://$server_name$request_uri;
}

server {
    listen 443      ssl http2;
    listen [::]:443 ssl http2;
    server_name cloud.example.com;

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

    # Use Mozilla's guidelines for SSL/TLS settings
    # https://mozilla.github.io/server-side-tls/ssl-config-generator/
    ssl_certificate     /etc/ssl/nginx/cloud.example.com.crt;
    ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;

    # Prevent nginx HTTP Server Detection
    server_tokens off;

    # HSTS settings
    # 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 Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always;

    # set max upload size and increase upload timeout:
    client_max_body_size 512M;
    client_body_timeout 300s;
    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/wasm 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;

    # Pagespeed is not supported by Nextcloud, so if your server is built
    # with the `ngx_pagespeed` module, uncomment this line to disable it.
    #pagespeed off;

    # The settings allows you to optimize the HTTP2 bandwitdth.
    # See https://blog.cloudflare.com/delivering-http-2-upload-speed-improvements/
    # for tunning hints
    client_body_buffer_size 512k;

    # HTTP response headers borrowed from Nextcloud `.htaccess`
    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;

    # Remove X-Powered-By, which is an information leak
    fastcgi_hide_header X-Powered-By;

    # Specify how to handle directories -- specifying `/index.php$request_uri`
    # here as the fallback means that Nginx always exhibits the desired behaviour
    # when a client requests a path that corresponds to a directory that exists
    # on the server. In particular, if that directory contains an index.php file,
    # that file is correctly served; if it doesn't, then the request is passed to
    # the front-end controller. This consistent behaviour means that we don't need
    # to specify custom rules for certain paths (e.g. images and other assets,
    # `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
    # `try_files $uri $uri/ /index.php$request_uri`
    # always provides the desired behaviour.
    index index.php index.html /index.php$request_uri;

    # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
    location = / {
        if ( $http_user_agent ~ ^DavClnt ) {
            return 302 /remote.php/webdav/$is_args$args;
        }
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    # Make a regex exception for `/.well-known` so that clients can still
    # access it despite the existence of the regex rule
    # `location ~ /(\.|autotest|...)` which would otherwise handle requests
    # for `/.well-known`.
    location ^~ /.well-known {
        # The rules in this block are an adaptation of the rules
        # in `.htaccess` that concern `/.well-known`.

        location = /.well-known/carddav { return 301 /remote.php/dav/; }
        location = /.well-known/caldav  { return 301 /remote.php/dav/; }

        location /.well-known/acme-challenge    { try_files $uri $uri/ =404; }
        location /.well-known/pki-validation    { try_files $uri $uri/ =404; }

        # Let Nextcloud's API for `/.well-known` URIs handle all other
        # requests by passing them to the front-end controller.
        return 301 /index.php$request_uri;
    }

    # Rules borrowed from `.htaccess` to hide certain paths from clients
    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)  { return 404; }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console)                { return 404; }

    # Ensure this block, which passes PHP files to the PHP process, is above the blocks
    # which handle static assets (as seen below). If this block is not declared first,
    # then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
    # to the URI, resulting in a HTTP 500 error response.
    location ~ \.php(?:$|/) {
        # Required for legacy support
        rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;

        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;

        fastcgi_param modHeadersAvailable true;         # Avoid sending the security headers twice
        fastcgi_param front_controller_active true;     # Enable pretty urls
        fastcgi_pass php-handler;

        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;

        fastcgi_max_temp_file_size 0;
    }

    location ~ \.(?:css|js|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463, $asset_immutable";
        access_log off;     # Optional: Don't log access to assets

        location ~ \.wasm$ {
            default_type application/wasm;
        }
    }

    location ~ \.woff2?$ {
        try_files $uri /index.php$request_uri;
        expires 7d;         # Cache-Control policy borrowed from `.htaccess`
        access_log off;     # Optional: Don't log access to assets
    }

    # Rule borrowed from `.htaccess`
    location /remote {
        return 301 /remote.php$request_uri;
    }

    location / {
        try_files $uri $uri/ /index.php$request_uri;
    }
}

我们只需查找修改以下内容:

server_name cloud.example.com;  #更改为自己的域名
root /var/www/nextcloud;    #更改为你的nextcloud目录
ssl_certificate     /etc/ssl/nginx/cloud.example.com.crt;   #SSL证书目录,一般放.pem根证书
ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;   #SSL证书目录,.key私钥

其他都不需要改。保存退出。

第三步:创建数据库

输入以下命令创建nextcloud数据库:

mysql
use mysql;
create database nextcloud;
exit

数据库可以不创建,在程序安装时会自动创建

我的建议也是不用创建,有时候创建后反而容易出现问题

安装Nextcloud

输入你的域名访问,比如:cloud.example.com 进入到安装界面。

安装前可以确认一下Nextcloud目录权限,没权限的话安装时也会提示“服务器内部错误”

数据库地址这边要加上数据库的端口,比如MySQL默认端口是 3306

点击安装即可完成。

至此,NextCloud已经安装完成。

总结

Nextcloud私人网盘已经搭建完成,再回头看看,想想每一个步骤的含义,非常有意义。

Nginx服务配置篇·第三课:NextCloud部署安装最先出现在Forever Young

]]>
https://www.luxiyue.com/server/nginx%e6%9c%8d%e5%8a%a1%e9%85%8d%e7%bd%ae%e7%af%87%c2%b7%e7%ac%ac%e4%b8%89%e8%af%be%ef%bc%9anextcloud%e9%83%a8%e7%bd%b2%e5%ae%89%e8%a3%85/feed/ 0