/RemoteDownload

利用服务器加速下载(代理下载文件) Flask

Primary LanguagePython

RemoteDownload

RemoteDownload 是使用 Flask 制作的代理下载工具,用来解决网络环境不好的情况下的下载问题(如:github 的国内加速下载)。

简单的使用方法

  1. 克隆代码到服务器

    git clone https://github.com/AntonVanke/RemoteDownload.git
  2. 安装 Python

    cd RemoteDownload/
    pip3 install -r requirements.txt

    如果你没有Python

    apt install python3
    # or
    yum install python3
  3. 运行脚本

    python3 app.py
    # ssh 运行 nohup python3 app.py &

如果你执行的没有错误的话,你就可以访问ip:port(默认端口是5000)来打开网页。当然,你也可以更改templates/index.html来美化首页。

需要在安全组打开相应的端口

Nginx 反代

如果你的服务器有Nginx,你也可以通过修改配置文件来共存使用。

# ……
server {
        listen       80;
        server_name  www.example.com;
        root /usr/share/nginx/html;
        location / {
        		# 转发到 flask 的 5000
                proxy_pass       http://127.0.0.1:5000;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
# ……

修改后使用sudo nginx -s reload重载配置。

开机自启动

创建文件/etc/systemd/system/remotedownload.service,内容如下

[Unit]
Description=remotedownload
Documentation=https://github.com/AntonVanke/RemoteDownload

[Service]
Type=simple
StandardError=journal
ExecStart="/usr/bin/python3" "#此处写入`app.py`路径#"
ExecReload=/bin/kill -HUP $MAINPID
LimitNOFILE=51200
Restart=on-failure
RestartSec=1s

[Install]
WantedBy=multi-user.target

然后执行

systemctl enable remotedownload
systemctl start remotedownload