小编rin*_*inu的帖子

Nginx不会以上游未找到的主机开始

我使用nginx代理并为我保持远程服务器的持久连接.

我已经配置了大约15个与此示例类似的块:

upstream rinu-test {
    server test.rinu.test:443;
    keepalive 20;
}
server {
    listen 80;
    server_name test.rinu.test;
    location / {
        proxy_pass https://rinu-test;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header Host $http_host;
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是如果无法在一个或多个upstream块中解析主机名,则nginx将不会(重新)启动.我也不能使用静态IP,其中一些主机明确表示不会这样做,因为IP会发生变化.我看到这个错误消息的每个其他解决方案都说要摆脱upstream并在location块中做所有事情.这不可能,因为keepalive只有在upstream.

我可以暂时承受失去一台服务器但不是全部15台.

编辑:结果nginx不适合这个用例.应使用备用后端(上游)keepalive代理.我的答案是自定义Node.js替代方案.到目前为止,我还没有找到其他任何实际可行的替代方案.

nginx http-proxy

32
推荐指数
2
解决办法
3万
查看次数

PHP 7 - 在等待curl时执行代码

以下是我的工作代码示例.只需添加自己sleep.php这将sleep($_GET['sleep']);

class MultiCurl {
    private $mc;
    private $running;
    private $execStatus;

    public function __construct() {
        $this->mc = curl_multi_init();
    }

    public function addCurl($ch) {
        $code = curl_multi_add_handle($this->mc, $ch);

        if ($code === CURLM_OK || $code === CURLM_CALL_MULTI_PERFORM) {
            do {
                $this->execStatus = curl_multi_exec($this->mc, $this->running);
            } while ($this->execStatus === CURLM_CALL_MULTI_PERFORM);

            return $this->getKey($ch);
        }
        return null;
    }

    public function getNextResult() {
        if ($this->running) {
            while ($this->running && ($this->execStatus == CURLM_OK || $this->execStatus == CURLM_CALL_MULTI_PERFORM)) {
                usleep(2500);
                curl_multi_exec($this->mc, $this->running);

                $responses = $this->readResponses();
                if …
Run Code Online (Sandbox Code Playgroud)

php curl

7
推荐指数
1
解决办法
473
查看次数

标签 统计

curl ×1

http-proxy ×1

nginx ×1

php ×1