内容
显示
Nextcloud配置和优化
Nextcloud数据库索引修复
当Nextcloud数据库丢失索引时,可以通过命令行手动修复。请在Nextcloud安装根目录执行以下命令:
sudo -u www php occ db:add-missing-indices
例如,修复丢失的索引“mail_messages_msgid_idx”:
sudo -u www php occ db:add-missing-indices
修复后可以显著提高查询速度。
Nextcloud配置文件(config.php)
<?php
$CONFIG = array(
'objectstore' => array(
'class' => '\\OC\\Files\\ObjectStore\\S3',
'arguments' => array(
'bucket' => 'nextcloud-*******', // 存储桶名称(空间名称)
'autocreate' => false,
'key' => 'AKID***********', // 替换为用户的 SecretId
'secret' => '**********', // 替换为用户的 SecretKey
'hostname' => 'cos.<Region>.myqcloud.com', // 将 <Region> 修改为所属地域,如 ap-shanghai
'use_ssl' => true,
),
),
'instanceid' => 'oc82tpo2f',
'passwordsalt' => '2GdQCVNsIVYF1KLP3fT3woH69X',
'secret' => 'VSy0Y+/2wV7g4kvbiKSE0dSa2Yp1ajtvvZpgdV14Lsc',
'trusted_domains' => array(
0 => 'nextcloud.***.***',
), // nextcloud域名
'datadirectory' => '/www/nextcloud/data', // data路径,请根据实际情况修改
'dbtype' => 'mysql',
'version' => '27.1.5.1',
'overwrite.cli.url' => 'https://nextcloud.***.***/nextcloud',
'dbname' => 'nextcloud',
'dbhost' => 'localhost',
'dbport' => '',
'dbtableprefix' => 'oc_',
'mysql.utf8mb4' => true,
'dbuser' => 'nextcloud', // 数据库用户名
'dbpassword' => '******', // 数据库密码
'installed' => true,
'maintenance' => false,
'updater.secret' => '\$2y\$10\$0eTb6aJ4u3NAWwlQk2qkUOTlI3.0O6TGLwAQOCyUtH/wmCpC',
'theme' => '',
'loglevel' => 2,
'filelocking.enabled' => true,
'memcache.local' => '\\OC\\Memcache\\Redis',
'memcache.locking' => '\\OC\\Memcache\\Redis',
'redis' => array(
'host' => '127.0.0.1',
'port' => 6379,
'timeout' => 0.0,
'password' => '', // redis密码
),
'mail_smtpmode' => 'smtp',
'mail_sendmailmode' => 'smtp',
'mail_from_address' => '****', // 请根据实际情况修改
'mail_domain' => 'outlook.com', // 请根据实际情况修改
'mail_smtpauth' => 1,
'mail_smtphost' => 'smtp-mail.outlook.com', // 请根据实际情况修改
'mail_smtpport' => '587', // 请根据实际情况修改
'mail_smtpname' => '*****', // 请根据实际情况修改
'mail_smtppassword' => '****', // 请根据实际情况修改
'enabledPreviewProviders' => [
'OC\Preview\MP3',
'OC\Preview\TXT',
'OC\Preview\MarkDown',
'OC\Preview\OpenDocument',
'OC\Preview\Krita',
'OC\Preview\Imaginary',
],
'preview_imaginary_url' => 'http://<url of imaginary>',
);
Nextcloud性能优化
后台任务
设置cron.php每5分钟运行一次,cron.php的具体路径在nextcloud安装的根目录下。
crontab -u www -e
*/5 * * * * php -f /PathToNextcloud/cron.php
PHP配置优化
- 注释掉php.ini中的
output_buffering
设置:
; output_buffering = 4096
- 启用OPcache以提高性能:
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=32
opcache.max_accelerated_files=80000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=3
- 设置HSTS以提高安全性,在apache的配置文件中加入:
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
</IfModule>
完整性检查
如果Nextcloud文件完整性检查发现问题,可以根据文档中的指导进行修复。例如,.user.ini
文件缺失可以创建该文件并设置适当的open_basedir
,或者在宝塔面板中开启放跨站。
完整config.php设置
<?php
$CONFIG = array(
'instanceid' => 'xxxxxxxxxxx',
'passwordsalt' => 'xxxxxxxxxxxxxxxxxx',
'secret' => 'TNFR/+xxxxxxxxxxxxxxxxxxx/',
'trusted_domains' =>
array (
0 => 'nextcloud.guohao.asia',
),
'datadirectory' => '/www/wwwroot/nextcloud/data',
'dbtype' => 'mysql',
'version' => '24.0.5.1',
'overwrite.cli.url' => 'https://nextcloud.guohao.asia',
'dbname' => 'xxxxxxxxxxxx',
'dbhost' => 'localhost',
'dbport' => '',
'dbtableprefix' => 'oc_',
'mysql.utf8mb4' => true,
'dbuser' => 'xxxxxxxxxx',
'dbpassword' => 'xxxxxxxxx',
'installed' => true,
'app_install_overwrite' =>
array (
0 => 'tencentcloudcosconfig',
1 => 'files_external_onedrive',
),
// 缓存设置
'memcache.local' => 'OC\\Memcache\\Redis',
'memcache.distributed' => 'OC\\Memcache\\Memcached',
'redis' => [ #Redis
'host' => 'localhost', #Redis 服务器
'port' => 6379, #Redis 端口
'timeout' => 0.0, #Redis 超时设定
'password' => 'XXXXXXXXXXX', #Redis 密码
'dbindex' => 1, #Redis 数据库选择
],
'memcached_servers' => array( #Memcached 服务器
array('localhost', 11211),
),
'memcached_options' => array( #Memcached 选项
\Memcached::OPT_CONNECT_TIMEOUT => 50,
\Memcached::OPT_RETRY_TIMEOUT => 50,
\Memcached::OPT_SEND_TIMEOUT => 50,
\Memcached::OPT_RECV_TIMEOUT => 50,
\Memcached::OPT_POLL_TIMEOUT => 50,
\Memcached::OPT_COMPRESSION => true,
\Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
\Memcached::OPT_BINARY_PROTOCOL => true,
),
'cache_path' => '/www/wwwroot/nextcloud/cache', #缓存目录
'cache_chunk_gc_ttl' => 60*60*24, #缓存删除时间
// 腾讯云COS
'objectstore' =>
array (
'class' => '\\OC\\Files\\ObjectStore\\S3',
'arguments' =>
array (
'key' => 'XXXXXXXXXXXXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXX',
'bucket' => 'nextcloud-000000000',
'hostname' => 'cos.ap-beijing.myqcloud.com',
'use_ssl' => true,
'autocreate' => false,
),
),
// 电话区号
'default_phone_region' => 'CN',
);
解决Nextcloud无法更新应用
在config.php
中添加以下内容以启用应用商店:
'appstoreenabled' => true,
'appstoreurl' => 'https://www.orcy.net/ncapps/v1/',
更换为国内源(更新进度较官方略慢)。