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

Linux, PHP 2018/03/20

nextcloud可以看做是一款基于owncloud的私有云解决方案。如果只需要简单的使用nextcloud,最基本的部署环境只需要nginx(apache)+php即可。

记录一下在宝塔面板环境下搭建nextcloud的过程中出现的一些问题及解决。

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

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

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

Nextcloud 16.x

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

一、部署

部署的过程不再详述,总结一下就是:

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.
内存缓存未配置,为了提升使用体验,请尽量配置内存缓存。更多信息请参见文档。
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.PHP 的设置似乎有问题, 无法获取系统环境变量. 使用 getenv(\”PATH\”) 测试时仅返回空结果.

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

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

保存并重启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)可以通过互联网访问,为了安全起见需要禁止访问。所以解决方法是修改nextcloud绑定的网站配置文件,添加nextcloud常用目录禁止访问即可

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

添加完毕保存即可生效

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;";

保存即可生效

5.内存缓存未配置,为了提升使用体验,请尽量配置内存缓存

这个问题是指php的缓存模块没有安装,nextcloud支持APCu、Memcached、Redis等模块,选择其中一个安装。我之前写过一个宝塔面板PHP 7.x 编译安装APCu

编译安装完毕之后,从宝塔面板打开/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的推荐配置,保存并重启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出现的安全及设置警告均以逐一解决,看一下最终效果

=======以下为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方式发送邮件。

其实就是让你设置一个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的命令行,而nextcloud又是基于owncloud开发的,所以需要用到OCC来修复丢失的数据库索引。

修复命令为:

php occ db:add-missing-indices

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

出现如下错误

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”. 这会导致信息泄露

大意是,需要设置一个Referrer-Policy请求头来提高安全性。Nginx配置文件里添加:

add_header Referrer-Policy "no-referrer";

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

至此,Nextcloud升级到14.0.3后出现的一些新的警告提示已全部消灭干净

本文标签:


47 条评论

  • jeforce 评论于 回复

    你好,nginx搭建的nextcloud21.0.0,出现的问题怎么解决,自己尝试了多遍,还是解决不了,谢谢!
    &&&关于您的设置有一些警告。&&&
    您的网页服务器未正确设置以解析“/.well-known/webfinger”。更多信息请参见文档。
    您的网页服务器未正确设置以解析“/.well-known/nodeinfo”。更多信息请参见文档。

    • Tin 评论于 回复

      @jeforce
      我也是遇到这个问题呢,请问下你解决了吗?

    • Tin 评论于 回复

      @jeforce
      刚刚在网上找到以下解决方法,但是不知道正不正确不过错误确实消失了

      如果是通过宝塔面板安装,可以在 网站 > 你的域名 > 伪静态 中加入

      location = /.well-known/webfinger {

      return 301 $scheme://$host:$server_port/index.php/.well-known/webfinger;
      }

      location = /.well-known/nodeinfo {

      return 301 $scheme://$host:$server_port/index.php/.well-known/nodeinfo;
      }

      转载:https://blog.csdn.net/weixin_44473210/article/details/118655904

  • 哈哈 评论于 回复

    打开ncweb出现与服务器的连接断开如何破

  • chirophy 评论于 回复

    请教一下bug侠,16.0.1版本的nc,在应用界面出现未找到适合当前版本的应用要怎么解决呢,谷歌了也没有找到解决办法

    • Bug侠 评论于 回复

      @chirophy
      不好意思啊,我刚刚升级到16.0.1,并没有出现这个提示。能不能截个图呢? :萌:

      • chirophy 评论于 回复

        @Bug侠
        很奇怪,今早再看的时候又可以打开app商城了,我有点怀疑是nc服务器的问题 :二哈:

        • Bug侠 评论于 回复

          @chirophy
          那很有可能,我早上升级16.0.1的时候就卡在Downloading好几次,估计nc也用的土豆服务器~~ :doge:

    评论(本站已开启评论回复邮件通知功能,请如实填写邮箱以便及时收到回复)关闭回复