Compare commits

...

10 Commits

Author SHA1 Message Date
root
419adaa71e save 2024-11-23 05:46:17 -05:00
tlanyan
3ab44d04e2 docs: more comments 2021-02-19 19:55:23 +08:00
tlanyan
865abfc81c feat(index.php): return 302 when exceed size limit 2021-01-26 17:31:13 +08:00
tlanyan
435515e89a feat: add time in log 2021-01-13 17:29:23 +08:00
tlanyan
33ccd5898a fix: get ip in cli mode 2021-01-12 21:08:21 +08:00
tlanyan
8b5aa07b1f feat: log real ip 2021-01-12 17:48:27 +08:00
tlanyan
232c3907a7 docs: tip 2021-01-11 19:24:48 +08:00
tlanyan
f9b72b34fa style: footer style 2021-01-11 19:11:09 +08:00
tlanyan
d0555e729e style(favicon): add favicon 2021-01-11 19:06:57 +08:00
tlanyan
13208e4f93 docs: stop instruction 2021-01-09 15:12:14 +08:00
5 changed files with 58 additions and 51 deletions

View File

@ -1,6 +1,6 @@
# 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/>
@ -71,12 +71,14 @@ apt install -y nginx
### 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服务器。
接下来,浏览器打开网址,输入要加速下载的链接,查看加速效果。
**停止程序**:首先 `ps aux | grep -v grep | grep index.php` 找到进程号(输出的第二列)然后kill掉`kill -9 进程号`。
使用中遇到问题欢迎反馈。
## Tips

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -31,6 +31,9 @@ server {
}
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;
}
}

View File

@ -89,28 +89,14 @@
color: #7b7b7b;
position: relative;
align-self: flex-start;
}
.tips p, .example p {
margin-left: 1em;
}
.example {
margin-left: 10em;
}
.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;
margin-top: -3em;
}
</style>
<head>
@ -124,31 +110,19 @@
return false;
}
</script>
<link rel="icon" href="/favicon.ico">
<title>GitHub 文件加速PHP版本</title>
</head>
<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">
<img
src="https://ae01.alicdn.com/kf/H2fc84859291347418b11091fe0e508b8v.png"
style="width: 1.5em; margin-right: 0.2em; vertical-align: bottom"
/>GitHub 文件加速PHP版本
/>GitHub 文件加速
</h1>
<p style="margin-bottom: 40px;">本站仅供演示,如需可靠使用,请自行部署</p>
<form
action="./"
method="get"
style="padding-bottom: 40px"
target="_blank"
class="flex"
onsubmit="toSubmit(event)"
@ -167,6 +141,7 @@
<input class="block btn" type="submit" value="下载" />
<div class="example">
<h2>输入示例:</h2>
<p>分支源码https://github.com/tlanyan/ghproxy/archive/main.zip</p>
<p>
release源码https://github.com/tlanyan/yii2/archive/2.0.4.zip
@ -176,20 +151,31 @@
</p>
<p>分支文件https://github.com/tlanyan/ghproxy/blob/main/index.html</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 class="tips">
<h2>注意事项:</h2>
<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>release、archive直接反代加速文件会跳转至JsDelivr或cnpmjs.org加速下载</p>
<p><strong>注意:不支持项目文件夹</strong></p>
</div>
</form>
<p style="position: sticky; top: calc(100% - 2.5em)">
本项目为 <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 style="color: #3294ea" href="https://github.com/tlanyan/ghproxy"
target="_blank">tlanyan/ghproxy</a
>
<p>
本项目为 <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> 开发
</p>
<p>
<a href="https://laysense.cn/">上海来笙信息科技有限公司</a>提供
</p>
</body>
</html>

View File

@ -4,15 +4,15 @@ require(__DIR__ . '/vendor/autoload.php');
define('ROOT', __DIR__);
// listen address, change to 0.0.0.0 to handle public requests
define('ADDR', '127.0.0.1');
define("PORT", 8080);
define('ADDR', '0.0.0.0');
define("PORT", 10500);
// use jsdelivr/cnpmjs
define('JSDELIVR', true);
define('CNPMJS', true);
define('JSDELIVR', false);
define('CNPMJS', false);
// 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();
@ -29,15 +29,27 @@ $loop->run();
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();
// strip start /
$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') {
return serveStaticFiles($url);
}
// @notice: uncomment the following line to proxy any url!
// return proxy($req);
$exp1 = '/^https?:\/\/?github\.com\/.+?\/.+?\/(?:releases|archive)\/.*$/i';
$exp2 = '/^https?:\/\/?github\.com\/.+?\/.+?\/(?:blob)\/.*$/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) {
echo 'length: ', normalizeSize(intval($headers['Content-Length'][0])), "exceed limit", PHP_EOL;
// return direct link instead of error
return new React\Http\Message\Response(
503
302,
array(
'Location' => $url
)
);
}