一、先介绍oneindex是什么:
解释一:OneIndex 是一款针对大微软巨无霸 Onedrive 网盘的开源程序。他能够将在Onedrive 中的文件用目录形式展示出来,用户可以通过连接直接下载。甚至视频文件还可以在线播放!对于用大量空间需求的用户可以不用服务器空间,不用耗费服务器的流量!爽吧。。
解释二:Oneindex 是一款开源的 Onedrive 目录列表程序,可以直接列出 OneDrive 文件目录,提供文件直链下载,不占用服务器空间,不走服务器流量(文件存储在 OneDrive 上),支持 OneDrive 个人版和 OneDrive 商业版。
基于以上优点所以推荐给大家,搭建自己的网盘!战斗吧少年!
OneIndex 能够实现以下功能:
- 响应式,支持小屏设备
- 视频、音乐在线播放
- 图片在线预览
- 代码在线查看
- 支持文件夹加密
- 支持自定义头部、底部显示
- 支持文件上传
- 不断更新中……
搭建 Oneindex:
oneindex 安装 需要你的准备以下工作:
1 支持PHP 环境的vps或独立主机:
- 1PHP5.5或以上
- CURL
- congfig cache 读写权限
2 OneDrive 账号一枚 没有的请自行申请。。
3 (可选) 一个域名用于解析
4 开源项目地址:
https://github.com/donwa/oneindex
step by step:
分两步基本就可以完成任务:
- 将域名解析到新建的站点,上传程序文件并解压,
- 打开域名,绑定 onedrive 账号 API
命令行安装 oneindex:
官方版本 Oneindex :
git clone https://github.com/donwa/oneindex.git /var/www/oneindex
基于官方版本的修改版 Oneindex :
git clone https://github.com/0oVicero0/oneindex.git /var/www/oneindex
注意,如果源码选择修改版且要启用 redis 缓存模式,服务器需要安装 redis-server
和 php7.1-redis
使用如下命令安装:
apt install php7.1-redis -y
创建虚拟机
使用如下命令创建 Oneindex 虚拟机配置文件:
vim /etc/nginx/sites-available/oneindex
复制以下内容粘贴并保存。注意,在复制前请将 example.com 修改为自己的域名:
server {
listen 80;
index index.php;
server_name example.com; # 将 example.com 修改为自己的域名
root /var/www/oneindex;
# individual nginx logs for this gitlab vhost
access_log /var/log/nginx/example.com_access.log; # 将 example.com 修改为自己的域名
error_log /var/log/nginx/example.com_error.log; # 将 example.com 修改为自己的域名
location / {
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_param HTTP_PROXY "";
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
将虚拟机接入 nginx :
ln -s /etc/nginx/sites-available/oneindex /etc/nginx/sites-enabled/oneindex
授予访问权限并重载 nginx :
chown -R www-data:www-data /var/www/oneindex && systemctl reload nginx.service
配置 Oneindex
绑定 Onedrive
浏览器访问 example.com
便可看到 Oneindex 安装界面,如下图所示:
点击“下一步”按钮,开始配置 Oneindex 。配置 Oneindex 需要登陆自己的 Onedrive 账户,并分别获得 client_secret
和 client_id
。详细的配置过程详见下图动画:
设置 Oneindex
绑定 Onedrive 后访问 example.com
便可看到 Oneindex 程序界面。后台管理地址为 example.com/admin
,初始密码 oenindex
。后台设置比较简单,首先修改后台登陆密码;修改“基本设置”里的最后一项“去掉地址栏中的/?/ (需配合伪静态使用!!)”,打开该选项可以去掉网址中的 ?
,使地址看起来更美观。本文提供的虚拟主机配置里已经添加了适合于 Oneindex 的伪静态,因此该选项直接启用即可,启用后点击右下角的保存按钮生效;如果安装的是基于官方版本的修改版 Oneindex ,且服务器已经安装了 redis-server
和 php7.1-redis
,后台将缓存类型修改为 redis 以提高性能。
设置定时任务
按照官方的建议,添加定时任务定时刷新缓存和令牌,以提高 Oneindex 访问性能。使用如下命令添加定时任务:
crontab -e
复制以下内容粘贴并保存,以设置定时任务:
*/10 * * * * php /var/www/oneindex/one.php cache:refresh # 每隔十分钟刷新一次缓存
0 * * * * php /var/www/oneindex/one.php token:refresh # 每隔一小时刷新一次令牌
一键安装 oneindex:
Github地址:https://github.com/donwa/oneindex
系统要求:脚本只适用于Debian 8、9
,且无网站环境,会自动签发Let's Encrypt SSL
证书,请提前将域名解析至VPS
服务器。
运行命令:
wget https://www.moerats.com/usr/shell/OneIndex.sh && bash OneIndex.sh
安装完成后,打开域名,按照提示进行安装配置。
后台地址:https://xx.com/?/admin
,默认密码:oneindex
,网站根目录/home/wwwroot/xx.com
。
提示:这里好几个同学反映进不去后台,博主看了下原因,顺便再说下,安装好了后,需要先访问自己的域名,然后绑定OneDrive账号了才能访问后台,不然是进不去后台的!
绑定OneDrive
后建议先访问后台,如果前台出现HTTP ERROR 500
的情况,可以重新下载源码后再绑定账号,使用命令:
#将domain.com改成你的域名再运行以下命令
cd /home/wwwroot/domain.com
rm -rf ./*
git clone https://github.com/donwa/oneindex.git
mv oneindex/* ./
chmod -R 777 config/ cache/
特殊文件实现功能
README.md
、HEAD.md
、.password
特殊文件使用。
#在文件夹底部添加说明
在onedrive的文件夹中添加README.md文件,使用markdown语法。
#在文件夹头部添加说明
在onedrive的文件夹中添加HEAD.md文件,使用markdown语法。
#加密文件夹
在onedrive的文件夹中添加.password文件,填入密码,密码不能为空。
#直接输出网页
在onedrive的文件夹中添加index.html文件,程序会直接输出网页而不列目录,配合文件展示设置-直接输出效果更佳。
命令行功能
仅能在php cli
模式下运行,且以下命令均在网站根目录/home/wwwroot/xx.com
运行。
#清除缓存
php one.php cache:clear
#刷新缓存
php one.php cache:refresh
#刷新令牌:
php one.php token:refresh
#上传文件
php one.php upload:file 本地文件 [onedrive文件]
#上传文件夹
php one.php upload:folder 本地文件夹 [onedrive文件夹]