nextdev/geoffrey

HTTP 反向代理

安装: 14

依赖: 0

建议者: 0

安全: 0

星星: 0

分支: 0

类型:项目

1.0.1 2019-06-06 13:52 UTC

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 状态响应并打印它接收的有效(规范化的)请求和生成的响应。