Apache2 mod_proxy_fcgi 在每次请求后关闭连接

Apache2 mod_proxy_fcgi 在每次请求后关闭连接

我设置了mod_proxy_fcgiapache 和php-fpm。如果我正确阅读了 FCGI 规范,那么服务器之间通信的典型流程是在 Web 服务器和 FastCGI 服务器处于活动状态时保持它们之间的连接打开。但是我观察到了不同的行为。Apache 似乎在每次请求后都会关闭连接。

以下是相关部分httpd.conf

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

...

ProxyPass / fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/ ttl=120
ProxyErrorOverride on

我设置LogLeveldebug。当我循环运行几个请求时,我收到以下日志(请求之间的时间间隔很短,因此我真的不希望出现任何超时):

[Mon Oct 07 12:43:49.338770 2013] [authz_core:debug] [pid 29880:tid 140162482755328] mod_authz_core.c(828): [client 127.0.0.1:36279] AH01628: authorization result: granted (no directives)
[Mon Oct 07 12:43:49.338793 2013] [proxy_fcgi:debug] [pid 29880:tid 140162482755328] mod_proxy_fcgi.c(120): [client 127.0.0.1:36279] AH01060: set r->filename to proxy:fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/info.php
[Mon Oct 07 12:43:49.338802 2013] [proxy:debug] [pid 29880:tid 140162482755328] mod_proxy.c(1083): [client 127.0.0.1:36279] AH01143: Running scheme fcgi handler (attempt 0)
[Mon Oct 07 12:43:49.338807 2013] [proxy_http:debug] [pid 29880:tid 140162482755328] mod_proxy_http.c(2174): [client 127.0.0.1:36279] AH01113: HTTP: declining URL fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/info.php
[Mon Oct 07 12:43:49.338812 2013] [proxy_fcgi:debug] [pid 29880:tid 140162482755328] mod_proxy_fcgi.c(944): [client 127.0.0.1:36279] AH01076: url: fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/info.php proxyname: (null) proxyport: 0
[Mon Oct 07 12:43:49.338816 2013] [proxy_fcgi:debug] [pid 29880:tid 140162482755328] mod_proxy_fcgi.c(954): [client 127.0.0.1:36279] AH01078: serving URL //127.0.0.1:9000/usr/local/apache2/htdocs/info.php
[Mon Oct 07 12:43:49.338821 2013] [proxy:debug] [pid 29880:tid 140162482755328] proxy_util.c(2013): AH00942: FCGI: has acquired connection for (127.0.0.1)
[Mon Oct 07 12:43:49.338826 2013] [proxy:debug] [pid 29880:tid 140162482755328] proxy_util.c(2065): [client 127.0.0.1:36279] AH00944: connecting //127.0.0.1:9000/usr/local/apache2/htdocs/info.php to 127.0.0.1:9000
[Mon Oct 07 12:43:49.338887 2013] [proxy:debug] [pid 29880:tid 140162482755328] proxy_util.c(2187): [client 127.0.0.1:36279] AH00947: connected /usr/local/apache2/htdocs/info.php to 127.0.0.1:9000
[Mon Oct 07 12:43:49.339232 2013] [proxy:debug] [pid 29880:tid 140162482755328] proxy_util.c(2028): AH00943: FCGI: has released connection for (127.0.0.1)
[Mon Oct 07 12:43:49.343980 2013] [authz_core:debug] [pid 28752:tid 140162457577216] mod_authz_core.c(828): [client 127.0.0.1:36282] AH01628: authorization result: granted (no directives)
[Mon Oct 07 12:43:49.344001 2013] [proxy_fcgi:debug] [pid 28752:tid 140162457577216] mod_proxy_fcgi.c(120): [client 127.0.0.1:36282] AH01060: set r->filename to proxy:fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/info.php
[Mon Oct 07 12:43:49.344018 2013] [proxy:debug] [pid 28752:tid 140162457577216] mod_proxy.c(1083): [client 127.0.0.1:36282] AH01143: Running scheme fcgi handler (attempt 0)
[Mon Oct 07 12:43:49.344024 2013] [proxy_http:debug] [pid 28752:tid 140162457577216] mod_proxy_http.c(2174): [client 127.0.0.1:36282] AH01113: HTTP: declining URL fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/info.php
[Mon Oct 07 12:43:49.344028 2013] [proxy_fcgi:debug] [pid 28752:tid 140162457577216] mod_proxy_fcgi.c(944): [client 127.0.0.1:36282] AH01076: url: fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/info.php proxyname: (null) proxyport: 0
[Mon Oct 07 12:43:49.344033 2013] [proxy_fcgi:debug] [pid 28752:tid 140162457577216] mod_proxy_fcgi.c(954): [client 127.0.0.1:36282] AH01078: serving URL //127.0.0.1:9000/usr/local/apache2/htdocs/info.php
[Mon Oct 07 12:43:49.344038 2013] [proxy:debug] [pid 28752:tid 140162457577216] proxy_util.c(2013): AH00942: FCGI: has acquired connection for (127.0.0.1)
[Mon Oct 07 12:43:49.344043 2013] [proxy:debug] [pid 28752:tid 140162457577216] proxy_util.c(2065): [client 127.0.0.1:36282] AH00944: connecting //127.0.0.1:9000/usr/local/apache2/htdocs/info.php to 127.0.0.1:9000
[Mon Oct 07 12:43:49.344082 2013] [proxy:debug] [pid 28752:tid 140162457577216] proxy_util.c(2187): [client 127.0.0.1:36282] AH00947: connected /usr/local/apache2/htdocs/info.php to 127.0.0.1:9000
[Mon Oct 07 12:43:49.344397 2013] [proxy:debug] [pid 28752:tid 140162457577216] proxy_util.c(2028): AH00943: FCGI: has released connection for (127.0.0.1)

我看到这句话FCGI: has released connection for (127.0.0.1)一遍又一遍地重复。我查看了 Apache2 实现。以下是相关部分:

PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
                                               proxy_conn_rec *conn,
                                               server_rec *s)
{
    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00943)
                 "%s: has released connection for (%s)",
                 proxy_function, conn->worker->s->hostname);
    connection_cleanup(conn);

    return OK;
}

...

PROXY_DECLARE(int) ap_proxy_connection_reusable(proxy_conn_rec *conn)
{
    proxy_worker *worker = conn->worker;

    return ! (conn->close || !worker->s->is_address_reusable || worker->s->disablereuse);
}

...

static apr_status_t connection_cleanup(void *theconn)
{
    ...

    /* determine if the connection need to be closed */
    if (!ap_proxy_connection_reusable(conn)) {
        apr_pool_t *p = conn->pool;
        apr_pool_clear(p);
        conn = apr_pcalloc(p, sizeof(proxy_conn_rec));
        conn->pool = p;
        conn->worker = worker;
        apr_pool_create(&(conn->scpool), p);
        apr_pool_tag(conn->scpool, "proxy_conn_scpool");
    }

    ...
}

我添加了一些额外的日志并重新编译了 Apache,结果发现两者conn->close都是真的,也是worker->s->is_address_reusable假的。有什么线索可以说明哪里配置错误吗?

多谢!

相关内容