宝塔面板部署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:

  • oliver 评论于 回复

    此服务器没有可用的互联网连接:多个节点无法访问。这意味着某些功能比如挂载外部存储,更新通知以及安装第三方应用将无法工作。远程访问文件和发送通知邮件可能也不工作。启用这台服务器上的互联网连接以享用所有功能

    这个错误您有没有遇到过,有没有解决方法?

  • 呃呃呃 评论于 回复

    Apache2怎么自动隐藏index.php呢?

  • Nath 评论于 回复

    此服务器没有可用的互联网连接:多个节点无法访问。这意味着某些功能比如挂载外部存储,更新通知以及安装第三方应用将无法工作。远程访问文件和发送通知邮件可能也不工作。启用这台服务器上的互联网连接以享用所有功能。

    数据库中的一些列由于进行长整型转换而缺失。由于给较大的数据表添加索引会耗费一些时间,因此程序没有自动对其进行修复。您可以在 Nextcloud 运行时通过命令行手动执行 “occ db:add-missing-indices” 命令修复丢失的索引。该操作需要当整个实例变为离线状态后执行。查阅相关文档以获得更多详情。
    filecache.mtime
    filecache.storage_mtime

    大佬 求助。
    第一个提示有点看的有点懵
    运行pecl install smbclient的时候也显示无法下载

    第二个提示我运行了
    sudo -u www php occ db:add-missing-indices
    只有两行一个是checking 第二行就是done。但还是显示错误。

    • yyy 评论于 回复

      @Nath
      我也是这个问题,求解决。

    • 弦夕 评论于 回复

      @Nath
      同样,是这个问题。郁闷、。

    • 弦夕 评论于 回复

      @Nath
      同样,是这个问题。郁闷、。

  • Eric 评论于 回复

    我第三条按照步骤配置了,还是提示“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.” 咋办?

  • nnn 评论于 回复

    请问下这个错误有知道怎么解决吗?网上找了没有相关信息
    系统ubuntu 18.10 Nginx -Tengine2.2.3 PHP-7.2
    错误信息
    1》 检查服务器设置时出错
    2》 通过 HTTP 访问网站不安全。强烈建议您将服务器设置成 HTTPS 协议(这个能解决吗?局域网没必要一定上https)

    其他问题在你这里找到解决方法,非常感谢!

    • Bug侠 评论于 回复

      @nnn
      您好,如果NC能正常使用,这些提示都是可以忽略的。而且在每条提示的后面应该都是附带有解决方案的。
      =======
      第一个“检查服务器设置时出错”我倒是没有遇到过……
      第二个,可以给服务器添加IP或者域名SSL证书,通过WEB访问就没有这个提示了。

      • nnn 评论于 回复

        @Bug侠
        检查服务器设置时出错 <这个后面没有附带相关信息,我换了系统几个版本,ng也换了几个版本还是有这个问题?很奇怪

  • HenJi 评论于 回复

    大佬,请问nginx下如何把url中的index.php彻底隐藏。。
    这个伪静态规则好像怎么写也隐藏不掉。。

    • Bug侠 评论于 回复

      @HenJi
      参照:https://bugxia.com/197.html
      —————–
      主要就是把原来的这行(注意版本)
      include enable-php-72.conf;
      替换成
      location ~ [^/]\.php(/|$){
      try_files $uri =404;
      fastcgi_pass unix:/tmp/php-cgi-72.sock;
      fastcgi_index index.php;
      include fastcgi.conf;
      include pathinfo.conf;
      fastcgi_param front_controller_active true;
      }

      • HenJi 评论于 回复

        @Bug侠
        搞定了,感谢大佬! :萌:

  • 友人 评论于 回复

    nextcloud出14了 ,又有些问题了

    • Bug侠 评论于 回复

      @友人
      嗯,文章也更新了。感谢提醒

  • bin 评论于 回复

    Some files have not passed the integrity check. Further information on how to resolve this issue can be found in the
    新的一个问题 在请教下!
    Results
    =======
    – core
    – INVALID_HASH
    – .htaccess
    – .user.ini
    – EXTRA_FILE
    – .well-known/pki-validation/fileauth.txt

    Raw output
    ==========
    上面这3个文件都要删除? 我尝试都删除 提示依旧 重新扫描过!

    • Bug侠 评论于 回复

      @bin
      不应该啊,如果删除了,怎么可能还会扫描到这些文件。实在不行就重启下php或者服务器

      • bin 评论于 回复

        @Bug侠
        这3个文件都没用吗? 比如这个 user.ini 多站点,明明加过参数/dev/urandom,现在又要删除!

        • Bug侠 评论于 回复

          @bin
          .htaccess是apache的配置文件,你用的是nginx的话,这文件就没用
          .user.ini是php的控制文件,删掉也没什么影响
          .well-known/pki-validation/fileauth.txt这是你的个人文件,看路径好像是过什么认证产生的文件,如果没用也可以删掉

      • 言心攵 评论于 回复

        @Bug侠
        感谢教程,终于解决了所有问题,么么哒 :大笑: :大笑: :大笑:

        • Bug侠 评论于 回复

          @言心攵
          :咧嘴: 这个还是有点过时,宝塔现在更新了,有些模块安装很方便,不用自己编译。

          • Bug侠 评论于 回复

            @Bug侠
            回复测试

            • Bug侠 评论于 回复

              @Bug侠
              :嘻嘻:

      • zhaorui 评论于 回复

        @Bug侠
        不好意思啊。刚才评论发到另一篇文章里了。在这里重新发一下
        大哥,你这个真nb,按你的教程真的都解决了。但是nextcloud又双叒叕升级了。14.0.3又多了几个新的。大佬有时间能不能在更新一下。如下:
        您的网页服务器未正确设置以解析“/.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_filecache” 中无法找到索引 “fs_mtime” .
        HTTP的请求头 “Referrer-Policy” 未设置为 “no-referrer”, “no-referrer-when-downgrade”, “strict-origin” or “strict-origin-when-cross-origin”. 这会导致信息泄露. 请查阅 W3C 建议↗
        请仔细检查安装指南,并检查日志中是否有错误或警告。

        • Bug侠 评论于 回复

          @zhaorui
          刚好今天更新了一篇:https://bugxia.com/805.html

      • 弦夕 评论于 回复

        @Bug侠
        您好,Nextcloud 21 新版本出现了新的问题。
        您的网页服务器未正确设置以解析“/.well-known/webfinger”。更多信息请参见文档。
        您的网页服务器未正确设置以解析“/.well-known/nodeinfo”。更多信息请参见文档。
        您的安装没有设置默认的电话区域。这对验证配置设定中没有国家代码的电话号码而言是必需的。
        您正在通过安全连接访问实例,但是您的实例生成的 URL 不安全。 这很可能意味着您正在使用反向代理,并且覆盖配置变量未正确设置。

        感谢,不知道怎么下手了。

  • bin 评论于 回复

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

    请教下! 保存提示出错 ,不起作用,会是哪里问题? 谢谢

    • Bug侠 评论于 回复

      @bin
      如果保存的时候提示出错,那就是nginx配置的问题,检查一下提示第几行出错,报什么错

      • bin 评论于 回复

        @Bug侠
        就这行 location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
        deny all;
        }

        需要改目录嘛 ?

      • bin 评论于 回复

        @Bug侠
        保存时提示信息
        nginx: [emerg] “location” directive is not allowed here in /www/server/panel/vhost/nginx/cloud.mailpostfix.com.conf:61
        nginx: configuration file /www/server/nginx/conf/nginx.conf test failed

        • Bug侠 评论于 回复

          @bin
          哦,提示配置放的位置不对,你仔细检查一下。或者联系我邮箱,admin@bugxia.com

          • bin 评论于 回复

            @Bug侠
            搞定了! 谢谢

  • jevin 评论于 回复

    换amh会有这些么?:汗:

    • Bug侠 评论于 回复

      @jevin
      每个环境都不一样,不过遇到的问题肯定大同小异,参照这个来就可以了 :大笑: :大笑:

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