让自建nextcloud绕过cloudflare上传限制

What?

随着网络的普及,很多人都搭建起了属于自己的nextcloud私有网盘。而对于访问量较大,公开性较强的私有网盘站点来说,许多人通常会使用CDN来保护自身免受攻击。

使用了CDN之后对于私有网盘而言,绕不开的一个问题就是单文件上传大小的限制,比如源站服务器允许1G大小单文件,到了CDN这里却只允许100M,于是用户就只能上传100M了,非常不方便。

绕过上传限制的办法么 ~ 除了氪金,似乎就只有分片上传了。好在nextcloud本身支持web界面开启分片上传,以下是具体方法(仅对web端有效,sync或者webdav仍然受单文件上传大小限制):

1.首先,确认自己的web服务器的php允许上传大小在自己满意的范围。(修改php.ini的max_upload_file_size数值实现)

2.打开nextcloud根目录,进入 apps/files/js目录,找到 jquery.fileupload.js,并使用编辑器打开。

3.跳转到154行附近,找到 maxChunkSize 这个选项。把这个选项后面的默认值改为其他数值。

默认情况:

            // To upload large files in smaller chunks, set the following option
            // to a preferred maximum chunk size. If set to 0, null or undefined,
            // or the browser does not support the required Blob API, files will
            // be uploaded as a whole.
            maxChunkSize: undefined,  //就是这里
            // When a non-multipart upload or a chunked multipart upload has been
            // aborted, this option can be used to resume the upload by setting
            // it to the size of the already uploaded bytes. This option is most
            // useful when modifying the options object inside of the "add" or
            // "send" callbacks, as the options are cloned for each file upload.
            uploadedBytes: undefined,

例如可以修改为 100000000 (约合98MB),并保存退出:

            // To upload large files in smaller chunks, set the following option
            // to a preferred maximum chunk size. If set to 0, null or undefined,
            // or the browser does not support the required Blob API, files will
            // be uploaded as a whole.
            maxChunkSize: 100000000,  //就是这里
            // When a non-multipart upload or a chunked multipart upload has been
            // aborted, this option can be used to resume the upload by setting
            // it to the size of the already uploaded bytes. This option is most
            // useful when modifying the options object inside of the "add" or
            // "send" callbacks, as the options are cloned for each file upload.
            uploadedBytes: undefined,

此时再打开web界面,刷新缓存以后就可以上传大于100M的单个文件了。

有什么副作用?

1.由于文件上传完毕后需要服务器组合,如果网络状况不佳或者服务器配置跟不上访问量,所以上传特大文件时可能会突然遇到无响应问题。

2.上传性能(上传单个文件所需要的时间)会延长很多。因为nextcloud对这方面并没有优化的很好。

点赞

发表评论

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