即使在代理服务备份后,mod_proxy 也会返回 503 错误

Ben*_*end 7 reverse-proxy mod-proxy 503-error apache-2.2

我将 Apache2 设置为由gunicorn提供的多个 python 应用程序的前端服务器。我使用 mod_proxy 的 Apache2 设置如下所示:

<VirtualHost *:80>
    ServerName example.com
    UseCanonicalName On
    ServerAdmin webmaster@localhost

    LogLevel warn
    CustomLog /var/log/apache2/example.com/access.log combined
    ErrorLog /var/log/apache2/example.com/error.log
    ServerSignature On

    Alias /media/ /home/example/example.com/pysrc/project/media/

    ProxyPass /media/ !
    ProxyPass / http://127.0.0.1:4711/
    ProxyPassReverse / http://127.0.0.1:4711/
    ProxyPreserveHost On
    ProxyErrorOverride Off
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

通常,此设置效果很好。但是我有一个问题:当我重新启动 gunicorn 进程(需要 2-5 秒)并且有来自 Apache 的请求时,该请求将失败并显示 503 错误。到现在为止还挺好。但是 Apache 不断返回 503 错误,即使在 gunicorn 进程备份之后也是如此。只有在 Apache 完全重新启动后,它才会从代理服务器恢复提供内容。

有没有办法解决这种行为?

小智 26

添加retry=0到您的 ProxyPass 行:

ProxyPass / http://127.0.0.1:4711/ retry=0
Run Code Online (Sandbox Code Playgroud)

mod_proxy 文档

连接池工作程序重试超时(以秒为单位)。如果到后端服务器的连接池工作线程处于错误状态,则 Apache 将不会将任何请求转发到该服务器,直到超时到期。这使得可以关闭后端服务器进行维护,并在稍后将其重新联机。值 0 表示始终在错误状态下重试工作程序,没有超时。