问题描述
直到昨天,我的服务器都运行良好.它正在运行 Redmine,它是最快乐的小服务器直到我的朋友"导入了我的小家伙无法接受的 SQL 表.不幸的是,在试图让小家伙做出回应一个小时后,我们不得不重启他.
现在重新启动后,我们在尝试访问连接到 Redmine 的域时收到 503 错误.它连接到 Mongrel 守护进程,我们使用 Apache 代理将所有连接定向到 Redmine 正在运行的端口
在服务器上使用 Lynx (http://localhost:8000
),您可以看到 Ruby 应用程序运行良好.但这一点在我的 Apache 配置文件中不起作用:
服务器名称 sub.example.comProxyPass/http://localhost:8000ProxyPassReverse/http://localhost:8000ProxyPreserveHost 开启日志级别调试</虚拟主机>
这是 Apache 的错误日志输出:
[debug] mod_proxy_http.c(54): proxy: HTTP: canonicalising URL//localhost:8000[调试] proxy_util.c(1335): [client 216.27.137.51] 代理: http: found worker http://localhost:8000 for http://localhost:8000/[调试] mod_proxy.c(756):运行方案http处理程序(尝试0)[调试] mod_proxy_http.c(1687): 代理: HTTP: 服务 URL http://localhost:8000/[调试] proxy_util.c(1755): 代理: HTTP: 已获得 (localhost) 的连接[调试] proxy_util.c(1815): 代理:将 http://localhost:8000/连接到 localhost:8000[调试] proxy_util.c(1908): 代理: 连接/到 localhost:8000[debug] proxy_util.c(2002): proxy: HTTP: fam 2 socket 创建以连接到本地主机[错误] (13)权限被拒绝:代理:HTTP:尝试连接到 127.0.0.1:8000 (localhost) 失败[错误] ap_proxy_connect_backend 为(本地主机)禁用工作器[调试] proxy_util.c(1773): 代理: HTTP: 已释放 (localhost) 的连接每当 Apache 检测到后端服务器关闭时,它都会以 503 响应至少 60 秒.这是默认行为.在您的示例中,如果您重新启动后端服务器(本示例中的 Rails)并且有人尝试在 Rails 准备好之前通过 Apache 代理访问它,那么无论您的后端现在是否启动",Apache 都会在接下来的 60 秒内返回 503.请参阅 ProxyPass 上的 apache 文档,其中说明:
重试 60 次
连接池工作重试超时(以秒为单位).如果到后端服务器的连接池工作线程处于错误状态,则 Apache 将不会将任何请求转发到该服务器,直到超时到期.这使得可以关闭后端服务器进行维护,并在稍后将其重新联机.值 0 表示始终在错误状态下重试工作程序,没有超时.
因此,如果您将代理通行证设置为包含 retry=0,则在重新启动后端服务时将看不到 503.这在开发过程中使用 Apache 作为反向代理时也很有用!例如:
ProxyPass/http://localhost:8000 retry=0
My server was doing just fine up until yesterday. It was running Redmine, and it was the happiest little server until my "friend" imported a SQL table that my little guy couldn't take. Unfortunately, after an hour of trying to get the lil guy to respond, we had to power cycle him.
Now after restart, we get a 503 error when trying to visit the domain connected to Redmine. It's hooked up to a Mongrel daemon, and we use Apache Proxy to direct all connections to the port Redmine is running on.
Using Lynx on the server (http://localhost:8000
) you can see the Ruby application working fine. But this bit is not working in my Apache configuration file:
<VirtualHost *:80>
ServerName sub.example.com
ProxyPass / http://localhost:8000
ProxyPassReverse / http://localhost:8000
ProxyPreserveHost on
LogLevel debug
</VirtualHost>
Here's the error log output for Apache:
[debug] mod_proxy_http.c(54): proxy: HTTP: canonicalising URL //localhost:8000 [debug] proxy_util.c(1335): [client 216.27.137.51] proxy: http: found worker http://localhost:8000 for http://localhost:8000/ [debug] mod_proxy.c(756): Running scheme http handler (attempt 0) [debug] mod_proxy_http.c(1687): proxy: HTTP: serving URL http://localhost:8000/ [debug] proxy_util.c(1755): proxy: HTTP: has acquired connection for (localhost) [debug] proxy_util.c(1815): proxy: connecting http://localhost:8000/ to localhost:8000 [debug] proxy_util.c(1908): proxy: connected / to localhost:8000 [debug] proxy_util.c(2002): proxy: HTTP: fam 2 socket created to connect to localhost [error] (13)Permission denied: proxy: HTTP: attempt to connect to 127.0.0.1:8000 (localhost) failed [error] ap_proxy_connect_backend disabling worker for (localhost) [debug] proxy_util.c(1773): proxy: HTTP: has released connection for (localhost)
Apache will respond with 503's for at least 60 seconds any time it detects that the backend server is down. This is the default behavior. As in your example, if you restart your backend server (Rails in this example) and someone tries to access it through the Apache proxy before Rails is ready then Apache will return 503's for the next 60 seconds regardless if your backend is now 'up'. Please see the apache docs on ProxyPass where it states:
So if you set your Proxy Pass to include retry=0 you won't see the 503's when you restart your backend service. This is also useful when using Apache as reverse proxy during development! For example:
这篇关于为什么我会收到 Apache Proxy 503 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!