# EasyUpload **Repository Path**: acc8226/easy-upload ## Basic Information - **Project Name**: EasyUpload - **Description**: EasyUpload 是一个极简的文件上传与浏览服务,基于 Flask 开发。 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-07-10 - **Last Updated**: 2025-08-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 理论上只依赖 flask,因此使用 `pip install flask` 即可。但实际上可能用到二维码分享的功能。 ```sh pip install Flask pip install PyYAML pip install qrcode[pil] ``` 服务器部署目前用的是 gunicorn (windows 环境不适用,建议使用 waitress) ```sh pip install gunicorn # windows 则是 waitress # pip install waitress ``` 如果你使用的是虚拟环境(推荐): ```sh pip freeze > requirements-dev.txt ``` ✅ 部署时如何使用? ```sh python3 -m venv venv source venv/bin/activate pip install -r requirements-dev.txt ``` ✅ 如果你是用命令行直接启动的 Gunicorn: gunicorn -w 4 -b 0.0.0.0:80 app:app 按 Ctrl + C(适用于前台运行)就可以中断并停止 Gunicorn。 -w 4:使用 4 个 worker 进程 -b 0.0.0.0:8000:监听所有 IP 的 8000 端口 app:app:你的 Flask 应用对象 如果是测试环境,可以改成 1 个。 ```sh mkdir log gunicorn -b 0.0.0.0:80 --backlog 1 -w 1 --access-logfile log/access.log -p gunicorn.pid --error-logfile log/error.log app:app ``` 由于 gunicorn 依赖于 fcntl 模块,而该模块在 Windows 上不可用。因此这里可以使用 Waitress 作为 Windows 上的 WSGI 服务器来运行 Flask 应用。 使用方法 ```sh waitress-serve --listen=0.0.0.0:80 app:app ``` ✅ 方法 3:使用 pkill 一键杀死所有 Gunicorn 进程 ```sh pkill gunicorn 或者强制 pkill -9 gunicorn ``` 在 /etc/nginx/nginx.conf 中导入 conf.d 文件夹下的所有模块 ```conf http { ... include /etc/nginx/conf.d/*.conf; # include /etc/nginx/sites-enabled/*; 如果设置反向代理不一样,需要修改或者直接注释改行 ... } ``` 接着可以使用 venv 环境,先进行测试 `/media/greatwall/个人/下载2/code/easy-upload/venv/bin/gunicorn -w 1 -b 0.0.0.0:5555 app:app` 确认 command 命令无误后,则可以自定义 mpan.conf 配置 ```conf [program:mpan] command=/media/greatwall/个人/下载2/code/easy-upload/venv/bin/gunicorn -w 1 -b 0.0.0.0:5555 app:app autostart=true autorestart=true stopasgroup=true killasgroup=true stderr_logfile=/var/log/mpan.err.log stdout_logfile=/var/log/mpan.out.log user=greatwall directory=/media/greatwall/个人/下载2/code/easy-upload ``` ```conf server { listen 80; # 监听 80 端口 server_name localhost; # 指定访问的域名或 IP,这里为 localhost # 针对某个虚拟主机单独设置,默认为 1 MB,会引发 client intended to send too large body: 4001317 bytes 这种错误 client_max_body_size 500m; location / { proxy_pass http://localhost:5555; # 将请求转发到 localhost:5555 proxy_set_header Host $host; # 保留原始请求的 Host 头 proxy_set_header X-Real-IP $remote_addr; # 将客户端的真实 IP 传递给后端服务 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 传递客户端的 IP 信息 proxy_set_header X-Forwarded-Proto $scheme; # 传递原始请求的协议(http/https) } } ``` 修改配置后记得 ```shell sudo nginx -t sudo systemctl restart nginx ``` ## 使用 Supervisor 后台运行和管理程序 在修改配置文件后,需要重新加载和更新 Supervisor 的配置: ```shell sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl restart mpan ``` 在浏览器地址栏手动输入 /browse 即可弹出管理员登录页;普通用户根本不知道这个入口存在。 1️⃣ 后端保持 /browse 的完整逻辑(已具备) 如果 ADMIN_PASSWORD 非空,首次访问 /browse 自动跳 管理员登录页。 登录成功后把 session['admin'] = True,后续直接显示文件列表。 http://localhost:5000/browse 文件浏览页 http://localhost:5000/super 超级密码登录页