宝塔安装Nextcloud的一些问题及处理方法

下载

官方稳定版:https://download.nextcloud.com/server/releases/
环境为LNMP,配置域名为:cloud.example.com,请自行替换。

  1. 根目录全删除

  2. 远程下载后解压
    目录类似:/www/wwwroot/h.xulihua.com/nextcloud

  3. 删除压缩包

网站设置:

  • 网站目录

  • SSL

  • 配置文件:

自行替换cloud.example.com和35行php版本号。

server {
    listen 80;
    listen [::]:80;
    server_name cloud.example.com;
    # enforce https
    return 301 https://$server_name$request_uri;
}
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name cloud.example.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/cloud.example.com/nextcloud;
 
    ssl_certificate    /etc/letsencrypt/live/cloud.example.com/fullchain.pem;
    ssl_certificate_key    /etc/letsencrypt/live/cloud.example.com/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    
    error_page 497 https://$host$request_uri;
    #nextcloud包含了403和404的错误页面
    error_page 403 /core/templates/403.php;
    error_page 404 /core/templates/404.php;
    
    #HSTS、缓存设置
    add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
    large_client_header_buffers 4 16k;
    client_max_body_size 10G; 
    fastcgi_buffers 64 4K;
    gzip off;
    
    #宝塔默认是include调用PHP相关配置,这里稍稍修改了一下,注意php版本
    #加入了front_controller_active这项参数以删除页面URL中的index.php
    location ~ [^/]\.php(/|$)
    {
        try_files $uri =404;
        fastcgi_pass  unix:/tmp/php-cgi-70.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
        include pathinfo.conf;
        fastcgi_param front_controller_active true;
    }
    
    #nextcloud一些关键目录的权限设置
    location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
        deny all;
    }
    #静态资源重定向1
    location ~* \/core\/(?:js\/oc\.js|preview\.png).*$ {
        rewrite ^ /index.php last;
    }
    #webdav重定向
    location / {
        rewrite ^ /index.php$uri;
        rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
        rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
        rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
        rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
        #静态资源重定向2,支持使用acme脚本在申请证书时对域名的验证
        if ($uri !~* (?:\.(?:css|js|svg|gif|png|html|ttf|woff)$|^\/(?:remote|public|cron|status|ocs\/v1|ocs\/v2)\.php|^\/\.well-known\/acme-challenge\/.*$)){
            rewrite ^ /index.php last;
        }
    }
    
    #静态资源重定向3
    location ~* \.(?:png|html|ttf|ico|jpg|jpeg)$ {
        try_files $uri /index.php$uri$is_args$args;
        access_log off;
    }
    
    location ~ ^/(?:updater|ocs-provider)(?:$|/) {
        try_files $uri/ =404;
        index index.php;
    }
    
    #对静态资源添加header
    location ~ \.(?:css|js|woff|svg|gif)$ {
        try_files $uri /index.php$uri$is_args$args;
        add_header Cache-Control "public, max-age=15778463";
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Robots-Tag none;
        add_header X-Download-Options noopen;
        add_header X-Permitted-Cross-Domain-Policies none;
        access_log off;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
    {
        expires      30d;
        access_log off; 
    }
    access_log  /www/wwwlogs/cloud.example.com.log;
}

安装PHP扩展:

加*为非必须

  • fileinfo

  • opcache

  • redis

  • apcu

  • *exif

安装smbclient

1. 先进入SSH,执行:

yum -y install libsmbclient libsmbclient-devel
pecl install smbclient

如果安装成功则显示如下内容:

Build process completed successfully
Installing '/www/server/php/70/lib/php/extensions/no-debug-non-zts-20151012/smbclient.so'
install ok: channel://pecl.php.net/smbclient-0.9.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=smbclient.so" to php.ini

复制上面smbclient.so的路径备用。

2. 编辑php.ini

进面板,编辑php配置文件,如果没有则在最后添加扩展库:

extension = /www/server/php/70/lib/php/extensions/no-debug-non-zts-20151012/smbclient.so
# 或
extension = "smbclient.so"

3. 重启PHP

在phpinfo里面查找smbclient,如果有显示则成功。

缓存设置:Redis+APCu

编辑添加nextcloud配置文件/www/wwwroot/cloud.example.com/nextcloud/config/config.php

'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\APCu',
'redis' => array(
     'host' => 'localhost',
     'port' => 6379,
      ),

getenv("PATH")为空

编辑(注意PHP版本号):/www/server/php/70/etc/php-fpm.conf
最后添加:env[PATH] = /usr/local/bin:/usr/bin:/bin:/usr/local/php/bin

PHP 无法访问 /dev/urandom

网站根目录,编辑.user.ini

open_basedir=/www/wwwroot/cloud.example.com/:/tmp/:/proc/:/dev/urandom

代码完整性检测

复制官方同名文件

内存缓存未配置

修改PHP.ini搜索:Zend Opcache
替换:

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

重启PHP。

添加新评论