Compare commits
10 Commits
1fab860a3c
...
419adaa71e
Author | SHA1 | Date | |
---|---|---|---|
|
419adaa71e | ||
|
3ab44d04e2 | ||
|
865abfc81c | ||
|
435515e89a | ||
|
33ccd5898a | ||
|
8b5aa07b1f | ||
|
232c3907a7 | ||
|
f9b72b34fa | ||
|
d0555e729e | ||
|
13208e4f93 |
@ -1,6 +1,6 @@
|
|||||||
# ghproxy
|
# ghproxy
|
||||||
|
|
||||||
Github文件下载加速PHP版,基于异步PHP框架 [ReactPHP](https://github.com/reactphp)开发。
|
Github文件下载加速PHP版,基于异步PHP框架 [ReactPHP](https://github.com/reactphp)开发,具有高性能、支持高并发的优点。
|
||||||
|
|
||||||
演示站点:<https://gh.2i.gs>,教程文章:<https://tlanyan.me/php-version-ghproxy/>
|
演示站点:<https://gh.2i.gs>,教程文章:<https://tlanyan.me/php-version-ghproxy/>
|
||||||
|
|
||||||
@ -71,12 +71,14 @@ apt install -y nginx
|
|||||||
|
|
||||||
### 4. 启动程序
|
### 4. 启动程序
|
||||||
|
|
||||||
进入项目文件夹,执行 `nohup php index.php &`,也可以在 tmux/screen 等终端窗口内执行 `php index.php` 启动程序。
|
进入项目文件夹,执行 `nohup php index.php > /var/log/ghproxy.log 2>&1 &`,也可以在 tmux/screen 等终端窗口内执行 `php index.php` 启动程序。
|
||||||
|
|
||||||
部署了Nginx的前端web服务器的,请重启web服务器。
|
部署了Nginx的前端web服务器的,请重启web服务器。
|
||||||
|
|
||||||
接下来,浏览器打开网址,输入要加速下载的链接,查看加速效果。
|
接下来,浏览器打开网址,输入要加速下载的链接,查看加速效果。
|
||||||
|
|
||||||
|
**停止程序**:首先 `ps aux | grep -v grep | grep index.php` 找到进程号(输出的第二列),然后kill掉:`kill -9 进程号`。
|
||||||
|
|
||||||
使用中遇到问题欢迎反馈。
|
使用中遇到问题欢迎反馈。
|
||||||
|
|
||||||
## Tips
|
## Tips
|
||||||
|
BIN
favicon.ico
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
@ -31,6 +31,9 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location ^~ /http {
|
location ^~ /http {
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header REMOTE_ADDR $remote_addr;
|
||||||
proxy_pass http://localhost:8080;
|
proxy_pass http://localhost:8080;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
66
index.html
66
index.html
@ -89,28 +89,14 @@
|
|||||||
color: #7b7b7b;
|
color: #7b7b7b;
|
||||||
position: relative;
|
position: relative;
|
||||||
align-self: flex-start;
|
align-self: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tips p, .example p {
|
||||||
|
margin-left: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.example {
|
.example {
|
||||||
margin-left: 10em;
|
margin-top: -3em;
|
||||||
}
|
|
||||||
.tips {
|
|
||||||
margin-left: 7.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tips > p:first-child::before {
|
|
||||||
position: absolute;
|
|
||||||
left: -3em;
|
|
||||||
content: "PS:";
|
|
||||||
color: #7b7b7b;
|
|
||||||
}
|
|
||||||
|
|
||||||
.example > p:first-child::before {
|
|
||||||
position: absolute;
|
|
||||||
left: -8em;
|
|
||||||
content: "合法输入示例:";
|
|
||||||
color: #7b7b7b;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<head>
|
<head>
|
||||||
@ -124,31 +110,19 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<link rel="icon" href="/favicon.ico">
|
||||||
<title>GitHub 文件加速(PHP版本)</title>
|
<title>GitHub 文件加速(PHP版本)</title>
|
||||||
</head>
|
</head>
|
||||||
<body class="flex">
|
<body class="flex">
|
||||||
<a
|
|
||||||
style="position: absolute; top: 0; right: 0"
|
|
||||||
href="https://github.com/tlanyan/ghproxy"
|
|
||||||
target="_blank"><img
|
|
||||||
width="149"
|
|
||||||
height="149"
|
|
||||||
referrerpolicy="no-referrer"
|
|
||||||
src="https://inews.gtimg.com/newsapp_ls/0/12025455907/0"
|
|
||||||
alt="Fork me on GitHub"
|
|
||||||
data-recalc-dims="1"
|
|
||||||
/></a>
|
|
||||||
<h1 style="margin-bottom: 10px">
|
<h1 style="margin-bottom: 10px">
|
||||||
<img
|
<img
|
||||||
src="https://ae01.alicdn.com/kf/H2fc84859291347418b11091fe0e508b8v.png"
|
src="https://ae01.alicdn.com/kf/H2fc84859291347418b11091fe0e508b8v.png"
|
||||||
style="width: 1.5em; margin-right: 0.2em; vertical-align: bottom"
|
style="width: 1.5em; margin-right: 0.2em; vertical-align: bottom"
|
||||||
/>GitHub 文件加速(PHP版本)
|
/>GitHub 文件加速
|
||||||
</h1>
|
</h1>
|
||||||
<p style="margin-bottom: 40px;">本站仅供演示,如需可靠使用,请自行部署</p>
|
|
||||||
<form
|
<form
|
||||||
action="./"
|
action="./"
|
||||||
method="get"
|
method="get"
|
||||||
style="padding-bottom: 40px"
|
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="flex"
|
class="flex"
|
||||||
onsubmit="toSubmit(event)"
|
onsubmit="toSubmit(event)"
|
||||||
@ -167,6 +141,7 @@
|
|||||||
<input class="block btn" type="submit" value="下载" />
|
<input class="block btn" type="submit" value="下载" />
|
||||||
|
|
||||||
<div class="example">
|
<div class="example">
|
||||||
|
<h2>输入示例:</h2>
|
||||||
<p>分支源码:https://github.com/tlanyan/ghproxy/archive/main.zip</p>
|
<p>分支源码:https://github.com/tlanyan/ghproxy/archive/main.zip</p>
|
||||||
<p>
|
<p>
|
||||||
release源码:https://github.com/tlanyan/yii2/archive/2.0.4.zip
|
release源码:https://github.com/tlanyan/yii2/archive/2.0.4.zip
|
||||||
@ -176,20 +151,31 @@
|
|||||||
</p>
|
</p>
|
||||||
<p>分支文件:https://github.com/tlanyan/ghproxy/blob/main/index.html</p>
|
<p>分支文件:https://github.com/tlanyan/ghproxy/blob/main/index.html</p>
|
||||||
<p>API请求:https://api.github.com/repos/reactphp/http/releases/latest</p>
|
<p>API请求:https://api.github.com/repos/reactphp/http/releases/latest</p>
|
||||||
|
<h2>您还可以:</h2>
|
||||||
|
<p>在任意github链接前加入https://ghproxy.layso.de/即可加速下载</p>
|
||||||
|
<p>如:https://ghproxy.layso.de/https://github.com/tlanyan/yii2/archive/2.0.4.zip</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="tips">
|
<div class="tips">
|
||||||
|
<h2>注意事项:</h2>
|
||||||
<p>
|
<p>
|
||||||
右键复制出来的链接都是符合标准的。
|
右键复制出来的链接都是符合标准的,<strong>但不支持项目文件夹</strong>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="tips">
|
||||||
|
<h2>浏览器插件</h2>
|
||||||
|
<p>
|
||||||
|
Edge浏览器可以前往<a href="https://microsoftedge.microsoft.com/addons/detail/github%E5%8A%A0%E9%80%9F/alhnbdjjbokpmilgemopoomnldpejihb?hl=zh-CN" target="_blank">Edge插件市场</a>安装插件,在扩展选项的“加速列表”填写 https://ghproxy.layso.de/ 其他保持默认保存即可
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
安装插件后访问github会自动展示加速下载链接
|
||||||
</p>
|
</p>
|
||||||
<p>release、archive直接反代加速,文件会跳转至JsDelivr或cnpmjs.org加速下载</p>
|
|
||||||
<p><strong>注意:不支持项目文件夹</strong></p>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<p style="position: sticky; top: calc(100% - 2.5em)">
|
<p>
|
||||||
本项目为 <a href="https://github.com/hunshcn/gh-proxy" target="_blank">gh-proxy</a> 的PHP版本,基于 <a href="https://github.com/reactphp" target="_blank">ReactPHP</a> 开发,开源于GitHub
|
本项目为 <a href="https://github.com/hunshcn/gh-proxy" target="_blank">gh-proxy</a> 的PHP版本,由 <a href="https://tlanyan.me" target="_blank">tlanyan</a> 基于 <a href="https://github.com/reactphp" target="_blank">ReactPHP</a> 开发
|
||||||
<a style="color: #3294ea" href="https://github.com/tlanyan/ghproxy"
|
</p>
|
||||||
target="_blank">tlanyan/ghproxy</a
|
<p>
|
||||||
>
|
由<a href="https://laysense.cn/">上海来笙信息科技有限公司</a>提供
|
||||||
</p>
|
</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
30
index.php
30
index.php
@ -4,15 +4,15 @@ require(__DIR__ . '/vendor/autoload.php');
|
|||||||
define('ROOT', __DIR__);
|
define('ROOT', __DIR__);
|
||||||
|
|
||||||
// listen address, change to 0.0.0.0 to handle public requests
|
// listen address, change to 0.0.0.0 to handle public requests
|
||||||
define('ADDR', '127.0.0.1');
|
define('ADDR', '0.0.0.0');
|
||||||
define("PORT", 8080);
|
define("PORT", 10500);
|
||||||
|
|
||||||
// use jsdelivr/cnpmjs
|
// use jsdelivr/cnpmjs
|
||||||
define('JSDELIVR', true);
|
define('JSDELIVR', false);
|
||||||
define('CNPMJS', true);
|
define('CNPMJS', false);
|
||||||
|
|
||||||
// download size limit, defaults to 2GB
|
// download size limit, defaults to 2GB
|
||||||
define('SIZE_LIMIT', 2 * 1024 * 1024 * 1024);
|
define('SIZE_LIMIT', 10 * 1024 * 1024 * 1024);
|
||||||
|
|
||||||
|
|
||||||
$loop = React\EventLoop\Factory::create();
|
$loop = React\EventLoop\Factory::create();
|
||||||
@ -29,15 +29,27 @@ $loop->run();
|
|||||||
|
|
||||||
|
|
||||||
function handler(Psr\Http\Message\ServerRequestInterface $req) {
|
function handler(Psr\Http\Message\ServerRequestInterface $req) {
|
||||||
|
$time = date('Y-m-d H:i:s');
|
||||||
|
$ip = $req->getHeader('REMOTE_ADDR');
|
||||||
|
if (!$ip) {
|
||||||
|
// app deal http requests
|
||||||
|
$ip = $req->getServerParams()['REMOTE_ADDR'];
|
||||||
|
} else {
|
||||||
|
// app is behind nginx
|
||||||
|
$ip = $ip[0];
|
||||||
|
}
|
||||||
$url = $req->getUri()->getPath();
|
$url = $req->getUri()->getPath();
|
||||||
// strip start /
|
// strip start /
|
||||||
$url = substr($url, 1);
|
$url = substr($url, 1);
|
||||||
echo "request url: ", $url, PHP_EOL;
|
echo "$time IP: $ip, request url: $url", PHP_EOL;
|
||||||
|
|
||||||
if (substr($url, 0, 4) !== 'http') {
|
if (substr($url, 0, 4) !== 'http') {
|
||||||
return serveStaticFiles($url);
|
return serveStaticFiles($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @notice: uncomment the following line to proxy any url!
|
||||||
|
// return proxy($req);
|
||||||
|
|
||||||
$exp1 = '/^https?:\/\/?github\.com\/.+?\/.+?\/(?:releases|archive)\/.*$/i';
|
$exp1 = '/^https?:\/\/?github\.com\/.+?\/.+?\/(?:releases|archive)\/.*$/i';
|
||||||
$exp2 = '/^https?:\/\/?github\.com\/.+?\/.+?\/(?:blob)\/.*$/i';
|
$exp2 = '/^https?:\/\/?github\.com\/.+?\/.+?\/(?:blob)\/.*$/i';
|
||||||
$exp3 = '/^https?:\/\/?github\.com\/.+?\/.+?\/(?:info|git-).*$/i';
|
$exp3 = '/^https?:\/\/?github\.com\/.+?\/.+?\/(?:info|git-).*$/i';
|
||||||
@ -143,8 +155,12 @@ function fetch(Psr\Http\Message\ServerRequestInterface $req) {
|
|||||||
|
|
||||||
if (isset($headers['Content-Length']) && intval($headers['Content-Length'][0]) > SIZE_LIMIT) {
|
if (isset($headers['Content-Length']) && intval($headers['Content-Length'][0]) > SIZE_LIMIT) {
|
||||||
echo 'length: ', normalizeSize(intval($headers['Content-Length'][0])), "exceed limit", PHP_EOL;
|
echo 'length: ', normalizeSize(intval($headers['Content-Length'][0])), "exceed limit", PHP_EOL;
|
||||||
|
// return direct link instead of error
|
||||||
return new React\Http\Message\Response(
|
return new React\Http\Message\Response(
|
||||||
503
|
302,
|
||||||
|
array(
|
||||||
|
'Location' => $url
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user