宝塔面板部署NextCloud逐一解决后台安全及设置警

本文详细介绍了在宝塔面板环境下部署Nextcloud的过程,包括解决PHP环境变量、fileinfo模块缺失、数据目录安全、HSTS设置等问题,以及Nextcloud 14.0.3版本后新增警告的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

nextcloud能看作是一款基于owncloud的私有云搞定计划。如果只需要简单的使用nextcloud,最基本的安装环境只需要nginx(apache)+php便可。


 

记载一下在宝塔面板环境下搭建nextcloud的途中中出现的一些问题及搞定。


 

=======更新========


 

Nextcloud 14.x版本后会出现一些新的警告,能参照:


 

宝塔面板安装NextCloud(14.0.3)一一搞定后台safe及设置警告


 

1、安装

安装的途中不再详述,总结一下就是:


 

1.宝塔面板部署nginx+php7.2(注意nextcloud从13.0版本开始才支持php 7.2)

 

2.下载压缩包并上传:https://download.nextcloud.com/server/releases/nextcloud-13.0.1.zip

 

3.服务端解压并访问

 

4.填写部署信息(使用者名、密钥),如果只是简单使用,可直接使用SQLite作为数据库,不需要MySQL


 

二、发现问题

经过安装,nextcloud已经能在web端或者客户端使用了,体会上去说,是没有任何影响的。但是从web端进入管理页面,会有如下错误

 

PHP 的设置似乎有问题, 没法获得系统环境变量. 使用 getenv(\”PATH\”) 测试时仅返回空成果.
Please check the installation documentation ↗ for PHP configuration notes and the PHP configuration of your server, especially when using php-fpm.
PHP 模块 ‘fileinfo’ 缺失. 咱们激烈提议启用此模块以便在 MIME 范例检测时博得最精确的成果.
Your data directory and files are probably accessible from the Internet. The .htaccess file is not working. It is strongly recommended that you configure your web server so that the data directory is no longer accessible, or move the data directory outside the web server document root.
The “Strict-Transport-Security” HTTP header is not set to at least “15552000” seconds. For enhanced security, it is recommended to enable HSTS as described in the security tips.
内存缓存未配置,为了提拔使用体会,请放量配置内存缓存。more信息请拜见文档。
The PHP OPcache is not properly configured. For better performance it is recommended to use the following settings in the php.ini:
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
请详细检查部署指南,并检查日记中能否有错误或警告。


 

作为1个逼迫症,不详决这些问题怎地行呢


 

3、一一搞定

1.PHP 的设置似乎有问题, 没法获得系统环境变量. 使用 getenv(\”PATH\”) 测试时仅返回空成果.

从宝塔文件管理,open /www/server/php/72/etc/php-fpm.conf,在其尾部增加一行


 

env[PATH] = /usr/local/bin:/usr/bin:/bin:/usr/local/php/bin

 

save并列启PHP便可搞定该问题

 

2.PHP 模块 ‘fileinfo’ 缺失. 咱们激烈提议启用此模块以便在 MIME 范例检测时博得最精确的成果

这个也很简单,由于php环境原始是没有部署 fileinfo这个扩展模块的,因而手动去宝塔PHP管理选项中部署 fileinfo扩展便可搞定该问题

 

3.Your data directory and files are probably accessible from the Internet. The .htaccess file is not working. It is strongly recommended that you configure your web server so that the data directory is no longer accessible, or move the data directory outside the web server document root.

大请安思是使用者的数据目录(data)能通过Internet访问,为了safe起见需要取缔访问。因而搞定方式是修正nextcloud绑定的站点配置文件,增加nextcloud常用目录取缔访问便可


 

location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {

    deny all;

}



 

增加终了save便可生效


 

4.The “Strict-Transport-Security” HTTP header is not set to at least “15552000” seconds. For enhanced security, it is recommended to enable HSTS as described in the security tips.

搞定方式仍是修正nextcloud绑定的站点配置文件,增加一行header信息


 

add_header Strict-Transport-Security "max-age=63072000;";



 

save便可生效


 

5.内存缓存未配置,为了提拔使用体会,请放量配置内存缓存

这个问题是指php的缓存模块没有部署,nextcloud支持APCu、Memcached、Redis等模块,挑选就中1个部署。伏笔VPS之前写过1个宝塔面板PHP 7.x 编译部署APCu


 

编译部署终了以后,从宝塔面板open/www/wwwroot/你的域名/config/config.php,手动给nextcloud的配置文件中增加一行设置,指定使用APCu作为缓存


 

'memcache.local' => '\OC\Memcache\APCu'



 

其他如Memcached、Redis的使用请参照官方文档:https://docs.nextcloud.com/server/13/admin_manual/configuration_server/caching_configuration.html


 

6.The PHP OPcache is not properly configured. For better performance it is recommended to use the following settings in the php.ini:

意义是php的OPcache模块没有部署配置,仍旧是从宝塔PHP设置面板中增加部署OPcache模块

 

部署完成后该提示仍旧是存在的,由于宝塔在部署OPcache模块后主动进入的配置不符合nextcloud的引荐配置,因而需要修正一下


 

找到OPcache的配置这一段,掉换成nextcloud的引荐配置,save并列启php便可生效

 

补充1:Some files have not passed the integrity check. Further information on how to resolve this issue can be found in the documentation

粗心是nextcloud目录下有一些不应出现的文件,点击“List of invalid files…”,会列出非常文件列表,删掉就中的文件便可搞定。

 

总结

至此,宝塔面板下部署nextcloud出现的safe及设置警告均以一一搞定,看一下最终结果

 

=======以下为NextCloud 14.0.x版本中新增的一些告警======


 

Use of the the built in php mailer is no longer supported. Please update your email server settings
您的网页服务器未准确设置以解析“/.well-known/caldav”
您的网页服务器未准确设置以解析“/.well-known/carddav”
The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically. By running “occ db:add-missing-indices” those missing indexes could be added manually while the instance keeps running. Once the indexes are added queries to those tables are usually much faster.
在数据表 “oc_share” 中没法找到索引 “parent_index” .
在数据表 “oc_filecache” 中没法找到索引 “fs_mtime” .
HTTP的请求头 “Referrer-Policy” 未设置为 “no-referrer”, “no-referrer-when-downgrade”, “strict-origin” or “strict-origin-when-cross-origin”. 这会导致信息泄露. 请查阅 W3C 提议


 

1.Use of the the built in php mailer is no longer supported. Please update your email server settings

粗心就是php自带的mail组件不再被nextcloud支持,需要使用smtp方法发送邮件。


 

实则就是让你设置1个smtp服务器信息,便于发送邮件,关于SMTP这里不再详述。

 

2.您的网页服务器未准确设置以解析“/.well-known/caldav”及您的网页服务器未准确设置以解析“/.well-known/carddav”

这两个警告能一齐搞定,出现该提示一般是由于这两个路径的伪静态设置有问题,导致没法一般访问。


 

搞定方式就是增加两行重定向配置


 

rewrite /.well-known/carddav /remote.php/dav permanent;

rewrite /.well-known/caldav /remote.php/dav permanent;



 

3.The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically. By running “occ db:add-missing-indices” those missing indexes could be added manually while the instance keeps running. Once the indexes are added queries to those tables are usually much faster.

在数据表”oc_share” 中没法找到索引”parent_index”
在数据表”oc_filecache” 中没法找到索引”fs_mtime”


 

粗心是说,数据库的一些索引丧失了,需要使用OCC修复一下。OCC是owncloud的command行,而nextcloud又是基于owncloud开拓的,因而需要用到OCC来修复丧失的数据库索引。


 

修复command为:


 

php occ db:add-missing-indices

 

SSH进入服务器nextcloud的根目录,并执行修复command

 

出现如下错误


 

Console has to be executed with the user that owns the file config/config.php
Current user: root
Owner of config.php: www
Try adding ‘sudo -u www ‘ to the beginning of the command (without the single quotes)


 

好吧,需要使用www使用者权限来修正,再次执行


 

sudo -u www php occ db:add-missing-indices



 

修复成功!


 

4.HTTP的请求头 “Referrer-Policy” 未设置为 “no-referrer”, “no-referrer-when-downgrade”, “strict-origin” or “strict-origin-when-cross-origin”. 这会导致信息泄露

粗心是,需要设置1个Referrer-Policy请求头来提升safe性。Nginx配置文件里增加:


 

add_header Referrer-Policy "no-referrer";



 

======================================================


 

至此,Nextcloudupgrade到14.0.3后出现的一些新的警告提示已全部覆灭彻底

 

 

 

 

原文链接:https://host.fubi.hk/foreshadowinghost/zhishiku/20181025/8384.html

### 如何在宝塔面板上安装 Nextcloud #### 准备工作 在开始之前,需确认服务器已成功安装并运行 CentOS 或其他兼容的操作系统,并通过 SSH 登录到服务器。此外,还需确保已经安装好宝塔面板[^1]。 #### 安装 LAMP/LNMP 环境 Nextcloud 需要一个 Web 服务器来运行其 PHP 脚本以及 MySQL 数据库支持。可以通过宝塔面板轻松完成 LNMP (Linux, Nginx, MariaDB/MySQL, PHP) 的安装。 - 在宝塔面板左侧菜单栏找到 **软件商店** 并选择适合的 PHP 版本(建议使用 PHP 7.4 或更高版本),同时安装 Nginx 和 MariaDB/MySQL[^2]。 #### 创建站点与数据库 - 返回首页点击 **网站** -> 添加站点 输入域名或者 IP 地址作为访问入口。 - 接着前往 **数据库** 页面新建用于存储数据的 MySQL/MariaDB 数据库实例[^3]。 #### 下载并解压 Nextcloud 文件包 - 使用 FTP 工具上传官方下载好的最新版 nextcloud.zip 到刚才创建好的根目录下;或者直接利用命令行工具 wget 获取远程资源文件 `wget https://download.nextcloud.com/server/releases/latest.zip` 同样放置于对应路径内[^4]。 #### 设置权限调整 为了使程序能够正常读写相关资料夹内的档案内容,请给予适当之档案所有权及群组设定指令如下: ```bash chown -R www-data:www-data /your/path/to/nextcloud/ chmod -R 755 /your/path/to/nextcloud/ ``` #### 初始化配置过程 打开浏览器输入所绑定之网址即可见初始化向导界面,按照提示填写必要参数比如管理员用户名密码还有先前准备完毕的数据源连接字符串等等信息即可完成初步部署操作[^5]。 #### 解决常见问题 如果遇到邮件发送失败的情况,则是因为内置PHPMailer已被弃用所致,因此需要修改电子邮件服务器的相关设置以适应新的需求标准。 ```php <?php $CONFIG = array ( 'mail_smtpmode' => 'smtp', 'mail_smtphost' => 'smtp.example.com', 'mail_smtpport' => '587', 'mail_smtpsecure'=> 'tls', 'mail_smtpauthtype'=>'LOGIN', 'mail_smtpauth' =>'1', 'mail_smtpname' =>'your_email@example.com', 'mail_smtppassword'=>'password' ); ?> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值