Compare commits

..

No commits in common. "419adaa71e9dfa070199a7b5ad0834285b467ac6" and "1fab860a3c673d87a319689447128363ebe5999d" have entirely different histories.

5 changed files with 51 additions and 58 deletions

View File

@ -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,14 +71,12 @@ apt install -y nginx
### 4. 启动程序 ### 4. 启动程序
进入项目文件夹,执行 `nohup php index.php > /var/log/ghproxy.log 2>&1 &`,也可以在 tmux/screen 等终端窗口内执行 `php index.php` 启动程序。 进入项目文件夹,执行 `nohup php index.php &`,也可以在 tmux/screen 等终端窗口内执行 `php index.php` 启动程序。
部署了Nginx的前端web服务器的请重启web服务器。 部署了Nginx的前端web服务器的请重启web服务器。
接下来,浏览器打开网址,输入要加速下载的链接,查看加速效果。 接下来,浏览器打开网址,输入要加速下载的链接,查看加速效果。
**停止程序**:首先 `ps aux | grep -v grep | grep index.php` 找到进程号(输出的第二列)然后kill掉`kill -9 进程号`。
使用中遇到问题欢迎反馈。 使用中遇到问题欢迎反馈。
## Tips ## Tips

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

View File

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

View File

@ -89,14 +89,28 @@
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-top: -3em; 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;
} }
</style> </style>
<head> <head>
@ -110,19 +124,31 @@
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 文件加速 />GitHub 文件加速PHP版本
</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)"
@ -141,7 +167,6 @@
<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
@ -151,31 +176,20 @@
</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> <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://tlanyan.me" target="_blank">tlanyan</a> 基于 <a href="https://github.com/reactphp" target="_blank">ReactPHP</a> 开发 本项目为 <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
</p> <a style="color: #3294ea" href="https://github.com/tlanyan/ghproxy"
<p> target="_blank">tlanyan/ghproxy</a
<a href="https://laysense.cn/">上海来笙信息科技有限公司</a>提供 >
</p> </p>
</body> </body>
</html> </html>

View File

@ -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', '0.0.0.0'); define('ADDR', '127.0.0.1');
define("PORT", 10500); define("PORT", 8080);
// use jsdelivr/cnpmjs // use jsdelivr/cnpmjs
define('JSDELIVR', false); define('JSDELIVR', true);
define('CNPMJS', false); define('CNPMJS', true);
// download size limit, defaults to 2GB // download size limit, defaults to 2GB
define('SIZE_LIMIT', 10 * 1024 * 1024 * 1024); define('SIZE_LIMIT', 2 * 1024 * 1024 * 1024);
$loop = React\EventLoop\Factory::create(); $loop = React\EventLoop\Factory::create();
@ -29,27 +29,15 @@ $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 "$time IP: $ip, request url: $url", PHP_EOL; echo "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';
@ -155,12 +143,8 @@ 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(
302, 503
array(
'Location' => $url
)
); );
} }
@ -195,4 +179,4 @@ function normalizeSize(int $size) {
} }
return round($size, 2) . 'GB'; return round($size, 2) . 'GB';
} }