为什么我会收到 Apache Proxy 503 错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/683052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:25:25  来源:igfitidea点击:

Why am I getting an Apache Proxy 503 error?

apache

提问by damon

My server was doing just fine up until yesterday. It was running Redmine, and it was the happiest little server untilmy "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.

直到昨天,我的服务器都做得很好。它正在运行Redmine,它是最快乐的小服务器,直到我的“朋友”导入了我的小家伙无法接受的 SQL 表。不幸的是,在试图让小家伙做出回应一个小时后,我们不得不重新启动他。

Now after restart, we get a 503 error when trying to visit the domain connected to Redmine. It's hooked up to a Mongreldaemon, and we use Apache Proxy to direct all connections to the port Redmine is running on.

现在重新启动后,我们在尝试访问连接到 Redmine 的域时收到 503 错误。它连接到一个Mongrel守护进程,我们使用 Apache 代理将所有连接定向到 Redmine 正在运行的端口。

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:

在服务器 ( http://localhost:8000)上使用 Lynx,您可以看到 Ruby 应用程序运行良好。但这一点在我的 Apache 配置文件中不起作用:

<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:

这是 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)

回答by exshovelrydr

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:

每当检测到后端服务器关闭时,Apache 都会以 503 响应至少 60 秒。这是默认行为。在您的示例中,如果您重新启动后端服务器(本示例中的 Rails)并且有人尝试在 Rails 准备好之前通过 Apache 代理访问它,那么无论您的后端现在是否“启动”,Apache 都会在接下来的 60 秒内返回 503 . 请参阅 ProxyPass 上的 apache 文档,其中指出:

retry 60

Connection pool worker retry timeout in seconds. If the connection pool worker to the backend server is in the error state, Apache will not forward any requests to that server until the timeout expires. This enables to shut down the backend server for maintenance, and bring it back online later. A value of 0 means always retry workers in an error state with no timeout.

重试 60

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

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:

因此,如果您将代理通行证设置为包含 retry=0,则在重新启动后端服务时将看不到 503。这在开发过程中使用 Apache 作为反向代理时也很有用!例如:

ProxyPass / http://localhost:8000retry=0

ProxyPass / http://localhost:8000retry=0

回答by user626710

Run following command

运行以下命令

# /usr/sbin/setsebool httpd_can_network_connect 1

OR

或者

# /usr/sbin/setsebool httpd_can_network_connect true

and after that restart httpd

然后重启httpd

# service httpd restart

回答by Andrew Flanagan

Are you sure they're restarting in the correct order? I've had weird issues where Apache starts, then Mongrel starts and although Mongrel is running, Apache still throws the proxy error.

您确定它们以正确的顺序重新启动吗?我在 Apache 启动时遇到了奇怪的问题,然后 Mongrel 启动,虽然 Mongrel 正在运行,但 Apache 仍然抛出代理错误。

I've solved this in the past with various incantations and restarts of Apache and eventually the gods are happy. It seems that sometimes the Mongrel processes don't properly shut down so you have to manually kill them. Here's a linkwith some [possible] help.

我过去曾用各种咒语和重启 Apache 解决了这个问题,最终众神都很高兴。似乎有时 Mongrel 进程无法正常关闭,因此您必须手动终止它们。这是一个包含一些 [可能] 帮助的链接

I ended up adding a "kill" option to my /etc/init.d/mongrel script because it happened so much. It stop Mongrel, killed all Mongrel sessions, started Mongrel and restarted Apache.

我最终在我的/etc/init.d/杂种脚本中添加了一个“kill”选项,因为它发生了很多。它停止 Mongrel,终止所有 Mongrel 会话,启动 Mongrel 并重新启动 Apache。

<snip>
    kill)
      echo "Stopping, killing, starting, and restarting Apache..."
      mongrel_cluster_ctl stop -c $CONF_DIR --clean
      killall -u mongrel
      mongrel_cluster_ctl start -c $CONF_DIR --clean
      /etc/init.d/httpd restart
      RETVAL=$?
  ;;
</snip>

Probably not a very good solution but the evil went away.

可能不是一个很好的解决方案,但邪恶消失了。

回答by nitecoder

Try running monit to monitor your mongrels behind Apache, and that way it can restart mongrels for you if they die or get too hungry for memory. If for any reason Apache still gets confused you may just have to gracefully restart apache and it should resolve itself, but for 99% of cases having monit watch over your mongrels should avoid this happening again. The other option is look into Phusion Passenger.

尝试运行 monit 来监视 Apache 背后的杂种,这样它就可以在杂种死了或对内存过于饥饿时为您重新启动。如果出于任何原因 Apache 仍然感到困惑,您可能只需要优雅地重新启动 apache 并且它应该会自行解决,但是对于 99% 的情况,通过 monit 监视您的杂种应该避免再次发生这种情况。另一种选择是查看 Phusion 乘客。

回答by Ajeet Khan

First check whether the port 8080 is listening or not by the following command

首先通过以下命令检查8080端口是否正在监听

netstat -tlpn

If not than restart the jenkins server by the following command

如果不是,请通过以下命令重新启动 jenkins 服务器

sudo /etc/init.d/jenkins start

It should work now. Hope it helps.

它现在应该可以工作了。希望能帮助到你。

回答by D. Hung

Fist, you must install selinux: (SELinux stands for Security-Enhanced Linux.)

拳头,你必须安装selinux:(SELinux 代表 Security-Enhanced Linux。)

apt-get install selinux

After that, you can enable Security Policy of SElinux by follow command:

之后,您可以通过以下命令启用 SElinux 的安全策略:

sed -i 's/SELINUX=.*/SELINUX=permissive/' /etc/selinux/config 

Notice:

注意:

#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.

Final,restart apache!

最后,重启apache!