使用 Apache 2.2.3 (Debian) mod_proxy 和 Jetty 6.1.18 出现代理错误 502“原因:从远程服务器读取错误”

89 jetty apache-2.2

Apache 在端口 :80 接收请求并将它们代理到端口 :8080 的 Jetty

The proxy server received an invalid response from an upstream server
The proxy server could not handle the request GET /.
Run Code Online (Sandbox Code Playgroud)

我的困境:一切正常(快速请求,几秒或几十秒长的请求处理正常)。当请求处理需要很长时间(几分钟?)会出现问题

如果我直接在端口 :8080 向 Jetty发出请求,则请求处理正常。所以问题很可能出现在我使用mod_proxy 的Apache 和 Jetty 之间。如何解决这个问题?

我已经尝试了一些与 KeepAlive 设置相关的“技巧”,但没有运气。这是我目前的配置,有什么建议吗?

#keepalive Off                     ## I have tried this, does not help
#SetEnv force-proxy-request-1.0 1  ## I have tried this, does not help
#SetEnv proxy-nokeepalive 1        ## I have tried this, does not help
#SetEnv proxy-initial-not-pooled 1 ## I have tried this, does not help
KeepAlive 20                       ## I have tried this, does not help
KeepAliveTimeout 600               ## I have tried this, does not help
ProxyTimeout 600                   ## I have tried this, does not help

NameVirtualHost *:80
<VirtualHost _default_:80>
    ServerAdmin webmaster@mydomain.fi

    ServerName www.mydomain.fi

    ServerAlias mydomain.fi mydomain.com mydomain www.mydomain.com

    ProxyRequests On
    ProxyVia On
    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>

    ProxyRequests Off
    ProxyPass / http://www.mydomain.fi:8080/ retry=1 acquire=3000 timeout=600
    ProxyPassReverse / http://www.mydomain.fi:8080/

    RewriteEngine On
    RewriteCond %{SERVER_NAME} !^www\.mydomain\.fi
    RewriteRule /(.*) http://www.mydomain.fi/$1 [redirect=301L]

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined
    ServerSignature On

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

这也是失败请求的调试日志:

74.125.43.99 - - [29/Sep/2010:20:15:40 +0300] "GET /?wicket:bookmarkablePage=newWindow:com.mydomain.view.application.reports.SaveReportPage HTTP/1.1" 502 355 "https://www.mydomain.fi/?wicket:interface=:0:2:::" "Mozilla/5.0 (Windows; U; Windows NT 6.1; fi; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"
[Wed Sep 29 20:20:40 2010] [error] [client 74.125.43.99] proxy: error reading status line from remote server www.mydomain.fi, referer: https://www.mydomain.fi/?wicket:interface=:0:2:::
[Wed Sep 29 20:20:40 2010] [error] [client 74.125.43.99] proxy: Error reading from remote server returned by /, referer: https://www.mydomain.fi/?wicket:interface=:0:2:::
Run Code Online (Sandbox Code Playgroud)

小智 106

我已经解决了这个问题。该Keepalive=On应插入ProxyPass配置行:

ProxyPass / http://www.dom.fi:8080/ retry=1 acquire=3000 timeout=600 Keepalive=On
Run Code Online (Sandbox Code Playgroud)

看到那个

Keepalive=On
Run Code Online (Sandbox Code Playgroud)

那里?这很关键;)

  • 我相信您可以将自己的答案标记为已接受。它将问题标记为已在系统中解决,供其他人查找。 (14认同)

Mar*_*ark 8

如果您的代理 url 不以/. 两条路径都应以 a/或都不以 a 结尾。


TCa*_*ell 5

你试过设置setenv proxy-initial-not-pooled 1吗?

参考这里