全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 4223|回复: 43

[经验] 写了一个网盘程序,代替 ys168

  [复制链接]
发表于 2021-12-30 20:07:12 | 显示全部楼层 |阅读模式
ys168 懂的都懂,可惜市面上没有找到差不多的网盘程序,自己用 Python 写了个,演示地址:

网址:141.94.115.2

密码:poiuytrewq

1C1G 50G 硬盘 50M 的小水管凑合用下,过两天就改密码了,以下为源码及安装指南。


安装要求:

Python >= 3.9,目前主流发行版应该只有 Debian11 能满足吧,更低 Python 版本懒得兼容了。

Nginx,版本没有特别要求,但因为用到了 X-Accel-Redirect,必须要使用 Nginx,当然你也可以自己兼容其他程序。


安装步骤:

以下安装步骤基于 Debian11 全程使用 Root 用户。

1. 创建文件夹,下载源码或者复制粘贴到 addfile.py 文件,这里直接下载

  1. mkdir /opt/addfile
  2. cd /opt/addfile
  3. wget http://141.94.115.2/addfile.py
复制代码


2. 编辑 addfile.py(可选步骤)

  1. ROOT = Path('/home/wwwroot/default')
  2. PASSWORD = 'poiuytrewq'
复制代码


将文件开头这两行换成你自己想要的目录和密码。

3. 安装依赖

  1. apt install python3-pip
  2. pip3 install index.py jinja2 uvicorn gunicorn
复制代码


4. 创建专用用户和用户组

  1. groupadd addfile
  2. useradd -s /sbin/nologin -M -g addfile addfile
复制代码


修改目录拥有者,不然无**常读写文件,记得对应你上面的程序和数据目录。

  1. chown -R addfile:addfile /opt/addfile
  2. chown -R addfile:addfile /home/wwwroot/default
复制代码


5. 创建并写入 /etc/systemd/system/addfile.service

  1. [Unit]
  2. Description=addfile daemon
  3. After=network.target

  4. [Service]
  5. Type=notify
  6. User=addfile
  7. Group=addfile
  8. RuntimeDirectory=addfile
  9. WorkingDirectory=/opt/addfile
  10. ExecStart=/usr/local/bin/gunicorn -k uvicorn.workers.UvicornWorker addfile:app
  11. ExecReload=/bin/kill -s HUP $MAINPID
  12. KillMode=mixed
  13. TimeoutStopSec=5
  14. PrivateTmp=true

  15. [Install]
  16. WantedBy=multi-user.target
复制代码


写入完毕后就可以启动了

  1. systemctl start addfile
  2. systemctl enable addfile
复制代码


6. 配置 Nginx 文件

  1.         location /
  2.         {
  3.             proxy_pass http://127.0.0.1:8000;
  4.         }

  5.         location /__x__/
  6.         {
  7.             internal;
  8.             alias /home/wwwroot/default/;
  9.         }
复制代码


关键的就这两行,重载配置就好了

  1. nginx -s reload
复制代码
 楼主| 发表于 2021-12-30 20:14:04 | 显示全部楼层

nginx 限制了 50M,这个自己部署的时候改下就行了
发表于 2021-12-30 20:12:45 | 显示全部楼层
不能放歌曲
发表于 2021-12-30 20:12:44 | 显示全部楼层
哈哈,赶紧关了。你看MJJ都传了啥上去。
发表于 2021-12-30 20:11:59 | 显示全部楼层
  1. 413 Request Entity Too Large
  2. nginx
复制代码
发表于 2021-12-30 20:08:48 | 显示全部楼层
绑定,这是小鸡上的盘?
 楼主| 发表于 2021-12-30 20:11:27 | 显示全部楼层
aipage 发表于 2021-12-30 20:08
绑定,这是小鸡上的盘?

小鸡上的,只能用本地文件
发表于 2021-12-30 20:13:31 | 显示全部楼层
能实现跟ys168一样吗?无限开分盘
发表于 2021-12-30 20:14:54 | 显示全部楼层
我登录了怎么还无法下载。
发表于 2021-12-30 20:14:58 | 显示全部楼层
能支持onedrive么
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-20 14:15 , Processed in 0.066151 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表