nextdev / geoffrey
1.0.1
2019-06-06 13:52 UTC
Requires
- php: ^7.2
- guzzlehttp/psr7: ^1.5
- php-http/curl-client: ^2
- php-http/message: ^1.7
- psr/http-client: ^1
- psr/http-factory: ^1
- psr/http-message: ^1
- psr/simple-cache: ^1
- slim/slim: ^3.1
Requires (Dev)
Suggests
- ext-mysqli: Needed for connections to mysql servers
- ext-xml: Needed for processing DOM-structured content
- ext-xsl: Needed for xmlStylesheet processor
This package is auto-updated.
Last update: 2024-09-07 01:39:58 UTC
README
为提供(有限)对(本地)旧服务访问的小型反向代理解决方案
安装
像这样简单:使用 Composer!
使用
通过配置您的 web 服务器来提供服务 ./www/index.php
。将环境变量 GEOFFREY_CONFIG
设置为 config.json
的位置。(默认为 ./.etc/config.json
)
地址映射
重写请求 URI 并从那里获取资源
{
"map": {
"frontdoor.example.com": "local.example.com/page123",
"frontdoor2.example.com": {
"url": "local.example.com/page456"
}
}
}
将请求转发到客户端自身无法到达的目的地
{
"map": {
"frontdoor.example.com": "192.168.0.2:8001",
"frontdoor2.example.com": {
"server": "192.168.1.2"
}
}
}
出站连接客户端
定义客户端选项
{
"client": {
"mariadbConnection123": {
"type": "mysql",
"host": "127.0.0.1",
"port": "3306",
"user": "exampleUser",
"pass": "pa$$word",
"dbname": "Geoffrey"
},
"mariadbConnection456": "mysql://exampleUser:pa$$word@127.0.0.1:3306/Geoffrey"
}
}
并使用它们来缓存响应
{
"cache": "mariadbConnection123"
}
重新配置底层的 cUrl-客户端
{
"client": {
"curl": {
"type": "curl",
"options": {
"CURLOPT_CONNECTTIMEOUT": 5
}
}
}
}
响应处理
根据它包含的 XSLT 处理指令转换 XML 资源
{
"processors": {
"xmlStylesheet": {}
}
}
将 HTML 页面的主体内容包装在某些头部和尾部中
{
"processors": {
"htmlContentFrame": {
"header": "cms.example.com/?get=header",
"footer": "cms.example.com/?get=footer"
}
}
}
头部和尾部的连接应生成一个有效的 HTML 文档。
或使用自己的代码
{
"processors": {
"text/x-owndocument": {
"factory": "vendorABC\\NamespaceXYZ\\ExampleProcessor::createMe",
"options": {
"foo": "bar"
}
}
}
}
工厂将首先接收 Geoffrey 实例,然后将配置条目作为第二个参数。
不要让讨厌的客人打扰到高手
告诉他们停止敲门(429)
{
"quota": {
"client": "mariaDBClient123",
"remoteAddr": {
"quota": 10,
"lifetime": 10
}
}
}
当客人太多时拒绝服务(503)
{
"quota": {
"client": "mariaDBClient123",
"global": {
"quota": 200,
"lifetime": 60
}
}
}
每个请求都会对配额减去 1。过去请求的累计权重为 last_recorded_weight * duration_without_hit / lifetime
。
如上例所示:60 秒没有命中后,过去请求将不会有对全局配额 200 的累计。
清理
运行 php ./script/evict.php
以使缓存和配额删除过时的数据。
更新/重置
php ./script/update.php
会在每次 composer update
后运行。任何其他时间调用它来重置缓存和配额。
调试
如果环境变量 GEOFFREY_DEBUG
设置为 1
,Geoffrey 将以 503 状态响应并打印它接收的有效(规范化的)请求和生成的响应。