打造自己的网盘(五)–NextCloud

打造自己的网盘(五)--NextCloud

一点废话

本来不想更新自建网盘系列,已经出掉了所有没用的吃灰机,但是看到Kimsufi搞了一波特价,正好他们系统有BUG还是怎么回事居然不要安装费,还和客服撕B两天把税免了所以又可以研究这方面了。自建网盘系列前面写的基本都是简单的东西,没技术含量,可能还有不少地方因为见识少所以有错误,本意就是提供个思路吧,简单写写程序的特性,取自己所需。

为啥又介绍Nextcloud呢?其实以前安装过owncloud,一个安装确实破事多,看着简单但是中间的小坑不断,所以一直没正经装过。很多主机商自带的模板又太老,追新控不能忍。近期有了大硬盘服务器,加上看到书生大佬的文章明白了很多,在大佬的帮助下终于安装成功了。

本篇以LNMP环境为例,很多人都使用LNMP,Apache环境下安装相对简单,但是owncloud/nextcloud的这个nginx伪静态问题确实事情多,所以就拿LNMP来做环境。

一、简单介绍NextCloud

在以前的文章中提到过NextCloud和OwnCloud,没有展开写,而且很明显这两个界面和官网都做的一模一样,到底有啥不一样?其实也没什么太多不同,NextCloud说白就是OwnCloud的继任者,OwnCloud原来开发的公司倒闭了,原班人马又组了一波继续开发。因为基于Owncloud所以nextcloud是非常成熟 大小写太麻烦了,全小写了 ,使用、安装和插件、客户端的支持没什么不同,基本都能拿来上手就用。

官网地址:https://nextcloud.com/

二、安装

本篇以Oneinstack的LNMP为例,介绍nextcloud的伪静态配置和优化等。

1.创建主机就不用说了,推荐上SSL。强烈推荐+官方建议使用PHP7.0,速度还是有质的提升的,本来nextcloud这货就比较臃肿,效率太低用着蛋疼。数据库的问题官方也有要求,不过Oneinstack已经默认调试好了,直接使用即可。

2.安装包下载:https://download.nextcloud.com/server/releases/nextcloud-12.0.0.zip 推荐wget,下载再上传太大了,容易断。设置好网站目录的权限,Oneinstack看官方推荐设置就行了:如何设置网站根目录权限?

3.直接访问网址,输入数据库和管理员信息,安装。安装完成后跳转到首页就会提示:”No input file specified.”,因为没有设置伪静态。

4.到/usr/local/nginx/conf/vhost/你的网站.conf,把以下代码加到里面,给出我的一份伪静态设置,其他参数根据自己实际情况稍加修改即可。

server {
  listen 80;
  listen 443 ssl http2;
  ssl_certificate /usr/local/nginx/conf/ssl/file.zhuti.ru.crt;
  ssl_certificate_key /usr/local/nginx/conf/ssl/file.zhuti.ru.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
  ssl_prefer_server_ciphers on;
  ssl_session_timeout 10m;
  ssl_session_cache builtin:1000 shared:SSL:10m;
  ssl_buffer_size 1400;
  add_header Strict-Transport-Security max-age=15768000;
  ssl_stapling on;
  ssl_stapling_verify on;
  server_name file.zhuti.ru;
  access_log /data/wwwlogs/file.zhuti.ru_nginx.log combined;
  index index.html index.htm index.php;
  root /data/wwwroot/file.zhuti.ru;
  if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
  
  include /usr/local/nginx/conf/rewrite/other.conf;
  #error_page 404 /404.html;
  #error_page 502 /502.html;
  
    #(可选)添加如下header主要为了安全
    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;
    #(可选)为了支持user_webfinger app
    rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
    rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
 
    #这儿是为了支持日历和联系人,建议加上
    location = /.well-known/carddav {
    return 301 $scheme://$host/remote.php/dav;
    }
    location = /.well-known/caldav {
    return 301 $scheme://$host/remote.php/dav;
    }
    #设置上传文件的最大大小(还和php里的那个设置有关)
    client_max_body_size 512M;
    fastcgi_buffers 64 4K;
    #最主要的,将所有请求转发到index.php上
    location / {
    rewrite ^ /index.php$uri;
    }
    #安全设置,禁止访问部分敏感内容
    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
    deny all;
    }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
    deny all;
    }
 
    #这部分吧,默认就有,不过有所不同,所以我合并了下,替换原来的就行
    location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param modHeadersAvailable true;
    fastcgi_param front_controller_active true;
    fastcgi_pass unix:/dev/shm/php-cgi.sock; #这边我改过,参照原来的
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
    include fastcgi.conf;
    }
 
    #安全设置,禁止访问部分敏感内容
    location ~ ^/(?:updater|ocs-provider)(?:$|/) {
    try_files $uri/ =404;
    index index.php;
    }
 
    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 ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
    try_files $uri /index.php$uri$is_args$args;
    access_log off;
    }
  
  location ~ [^/]\.php(/|$) {
    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
  }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  location ~ /\.ht {
    deny all;
  }
}

完成后 service nginx reload 即可。

5.程序优化

(1)“PHP 被设置为移除内联块, 这将导致多个核心应用无法访问.

这可能由缓存/加速器导致的, 例如 Zend OPcache 或 eAccelerator.”

这是因为我们还要对php.ini中Opcache的参数进行修改,改成下方的就行(Oneinstack的相关参数被拆分出来了,在/usr/local/php/etc/php.d/ext-opcache.ini 中)其它可以不用改,主要是那个opcache.save_comments=1 ,因为默认是0,改完重启php-fpm就行

顺手把fileinfo模块装了(用addon.sh就行),然后我们还需要配置下内存缓存,这个的话NextCloud支持的种类还是不少的,有APU、Memcached以及Redis。

其实吧,官方推荐APU或者Redis,最方便的是APU了,至于你们喜欢啥那随意,下面给出一些配置的栗子,都需要修改config目录中的config.php才行

①APU

在配置文件中添加如下

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

②Memcached

在配置文件中添加如下,这个是多个Memcached实例,单个自己改 (因为这货不能数据持久化,所以真的不推荐

'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\OC\Memcache\Memcached',
'memcached_servers' => array(
     array('localhost', 11211),
     array('server1.example.com', 11211),
     array('server2.example.com', 11211),
     ),

③Redis

在配置文件中添加如下,这个是通过TCP连接的

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

还有性能更好的UNIX连接

'memcache.local' => '\OC\Memcache\Redis',
'redis' => array(
     'host' => '/var/run/redis/redis.sock',
     'port' => 0,
     'dbindex' => 0,
     'password' => 'secret',
     'timeout' => 1.5,
      ),

同时,官方还推荐加入如下,来用于存储文件锁

'memcache.locking' => '\OC\Memcache\Redis',

还有个要改的地方就是Cron了,默认的Cron是AJAX的,效率不行,建议改成系统Cron任务

#-u是用于指定这个crontab是www用户的
crontab -u www -e
#这儿建议php使用完整路径,另外要改下cron.php的路径为你自己的
*/15  *  *  *  * php -f /data/wwwroot/你的网站/cron.php

啥?这些看不懂?那就用不着动了,反正不影响用。

请记得在解压NextCloud程序并转移文件的时候注意.htaccess .user.ini这俩,前者在Nginx下倒是不重要,后者请务必注意,因为这个是用于覆盖php.ini配置的,便于OwnCloud调整上传文件的大小,如果没有这个,在之前的Nginx部分你修改了那个最大大小是没有用的,还是会被php.ini中的限制住。

三、使用体验

进入首页后是这个样子,蓝白配还是挺不错的。

打造自己的网盘(五)--NextCloud

WebDAV功能,这个功能还是很实用的,Android推荐一款笔记软件:易码 可以同步通过WebDAV同步到自己的网盘。只要支持这个功能的客户端都能用。

打造自己的网盘(五)--NextCloud

左侧的功能区,可以收藏,可以做标签,还可以管理分享,很成熟实用的功能。

打造自己的网盘(五)--NextCloud

上传文件,创建文件夹和新建文本文档。

打造自己的网盘(五)--NextCloud

回收站功能,不怕手贱点错了。

打造自己的网盘(五)--NextCloud

相册功能。Nextcloud对图片浏览挺友好,相册功能实用很多。

打造自己的网盘(五)--NextCloud

多种格式预览,这个无需多言了,主流的都会支持,例如mp4、pdf、mp3、txt等。doc等office文档需要装插件。编辑office等在线办公工具可以去官网查看:https://nextcloud.com/collaboraonline/

打造自己的网盘(五)--NextCloud

多客户端支持,nextcloud这种老牌程序不用多说,绝大部分主流客户端都支持,去官网或者应用市场下载即可

这种老牌程序最强大的插件功能。非常丰富的插件,太多了不可能写完,所以截个图,在设置里面就能看到。nextcloud支持两步认证、外挂存储、在线办公、日历功能等等非常丰富,需要自己来研究来玩了。

打造自己的网盘(五)--NextCloud

设置后台,例如Email的验证可以当作是支持多用户吧。分享链接的管理和分享的设置。还可以设置个人帐号的动态分享,还有管理当前的会话,更安全。

打造自己的网盘(五)--NextCloud

打造自己的网盘(五)--NextCloud

打造自己的网盘(五)--NextCloud

打造自己的网盘(五)--NextCloud

打造自己的网盘(五)--NextCloud

四、使用总结

过了安装的坎就可以发现这个强大的程序,集成owncloud的底子所以nextcloud 非常成熟可靠。虽然偏向臃肿,但是nextcloud 更加成熟,插件的支持、多用户等等都对需求比较多的人来说非常棒。如果你需要一款功能强大的网盘程序,那么成熟的nextcloud将会是首选。

五、参考资料

本篇文章的写成参考了以下文章,感谢原作者的辛苦付出!

1.自建云盘系列——NextCloud (OwnCloud继任者)

2.Nextcloud官方使用文档:https://docs.nextcloud.com/server/12/user_manual/

原创文章,作者:zrj766,如若转载,请注明出处:https://www.zrj96.com/post-542.html

欢迎关注本站Telegram频道获取最新资讯:点击加入

(3)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
zrj766zrj766
上一篇 2017年6月13日 09:00
下一篇 2017年8月4日 15:10

相关推荐

回复 cc

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

评论列表(12条)

  • 吃茶
    吃茶 2019年11月28日 08:16

    我这边其实安装过,但是那个伪静态设置一直是个问题,总是设置不好,出问题,有时候index.php隐藏掉了,但是登录以后玉面就没有操作界面那种了,全是乱乱的文字了,
    还有就是我感觉nextcloud的盘中搜索不太好,好像就不支持中文搜索一样

  • ceeop
    ceeop 2019年4月26日 18:44

    你好,有一个小问题,ios客户端浏览任何文件都会下载下来,这个有办法解决吗?

  • XG
    XG 2018年6月14日 22:01

    The server was unable to complete your request.

    If this happens again, please send the technical details below to the server administrator.

    More details can be found in the server log.

  • abababa
    abababa 2018年6月12日 19:48

    [error] 4482#0: *1 rewrite or internal redirection cycle while processing “/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/”, client: 10.0.1.14, server: pan.test.net, request: “GET / HTTP/1.1”, host: “pan.test.net”

    nginx nextcloud rewrite problem

    upstream php-handler {
    #server 127.0.0.1:9000;
    server unix:/var/run/php-fpm725/php-fpm.socket;
    }

    server {
    listen 80;
    server_name pan.test.net;
    # enforce https
    return 301 https://$server_name$request_uri;
    }

    server {
    listen 443 ssl;
    server_name pan.test.net;

    ssl_certificate /etc/nginx/cert/nextcloud.crt;
    ssl_certificate_key /etc/nginx/cert/nextcloud.key;

    # Add headers to serve security related headers
    # Before enabling Strict-Transport-Security headers please read into this
    # topic first.
    add_header Strict-Transport-Security “max-age=15768000;
    includeSubDomains; preload;”;
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options “SAMEORIGIN”;
    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;

    # Path to the root of your installation
    root /var/www/npan/;

    location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
    }

    # The following 2 rules are only needed for the user_webfinger app.
    # Uncomment it if you’re planning to use this app.
    #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
    #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
    # last;

    location = /.well-known/carddav {
    return 301 $scheme://$host/remote.php/dav;
    }
    location = /.well-known/caldav {
    return 301 $scheme://$host/remote.php/dav;
    }

    # set max upload size
    client_max_body_size 512M;
    fastcgi_buffers 64 4K;

    # Disable gzip to avoid the removal of the ETag header
    gzip off;

    # Uncomment if your server is build with the ngx_pagespeed module
    # This module is currently not supported.
    #pagespeed off;

    error_page 403 /core/templates/403.php;
    error_page 404 /core/templates/404.php;

    location / {
    rewrite ^ /index.php$uri;
    }

    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
    deny all;
    }
    location ~ ^/(?:/.|autotest|occ|issue|indie|db_|console) {
    deny all;
    }

    location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])/.php(?:$|/) {
    include fastcgi_params;
    fastcgi_split_path_info ^(.+/.php)(/.*)$;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param HTTPS on;
    #Avoid sending the security headers twice
    fastcgi_param modHeadersAvailable true;
    fastcgi_param front_controller_active true;
    fastcgi_pass php-handler;
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
    }

    location ~ ^/(?:updater|ocs-provider)(?:$|/) {
    try_files $uri/ =404;
    index index.php;
    }

    # Adding the cache control header for js and css files
    # Make sure it is BELOW the PHP block
    location ~* /.(?:css|js)$ {
    try_files $uri /index.php$uri$is_args$args;
    add_header Cache-Control “public, max-age=7200”;
    # Add headers to serve security related headers (It is intended to
    # have those duplicated to the ones above)
    # Before enabling Strict-Transport-Security headers please read into
    # this topic first.
    add_header Strict-Transport-Security “max-age=15768000;
    includeSubDomains; preload;”;
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options “SAMEORIGIN”;
    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;
    # Optional: Don’t log access to assets
    access_log off;
    }

    location ~* /.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
    try_files $uri /index.php$uri$is_args$args;
    # Optional: Don’t log access to other assets
    access_log off;
    }
    }

    nginx重写出错呢?

  • 老狼
    老狼 2017年12月7日 07:50

    请问文中的.user.ini这个文件用于覆盖php.ini,什么意思?需要自己手动复制user.ini覆盖php.ini,我是新的不能再新的新手了。求指教

    • zrj766
      zrj766 2017年12月7日 10:43

      @老狼文件目录有user那个记得搬家的时候也带上,没有的话其实用不着理会。

  • cc
    cc 2017年10月3日 21:28

    .htaccess .user.ini
    这2个在LNMP 环境 下 不能删除掉吗?
    后台一直显示 文件不完整,安全检查!

    • zrj766
      zrj766 2017年10月3日 21:30

      @cc试试用WinSCP删除或者rm -rf命令单独删除。
      文件不完整如果不影响正常使用不用理会,如果影响了再重装试试,我没有遇到此问题。

  • seri
    seri 2017年9月17日 01:19

    :razz: 看到收费标准,我一个人 one user 应该free吧 – – :!:

  • 烟花易冷
    烟花易冷 2017年6月25日 19:36

    挺好的,实用