首页 文章

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

提问于
浏览
47

我的服务器直到昨天都做得很好 . 它正在运行Redmine,它是最快乐的小服务器 until 我的"friend"导入了一个我的小家伙无法接受的SQL表 . 不幸的是,经过一个小时的尝试让小伙伴做出回应,我们不得不重新启动他 .

现在重启后,我们在尝试访问连接到Redmine的域时遇到503错误 . 它连接到Mongrel守护程序,我们使用Apache Proxy将所有连接定向到Redmine正在运行的端口 .

在服务器上使用Lynx( http://localhost:8000 ),您可以看到Ruby应用程序正常运行 . 但是这个位在我的Apache配置文件中不起作用:

<VirtualHost *:80>
    ServerName sub.example.com
    ProxyPass / http://localhost:8000
    ProxyPassReverse / http://localhost:8000
    ProxyPreserveHost on
    LogLevel debug
</VirtualHost>

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

7 回答

  • 84

    只要检测到后端服务器出现故障,Apache就会用503响应至少60秒 . 这是默认行为 . 在您的示例中,如果您重新启动后端服务器(在此示例中为Rails)并且有人在Rails准备好之前尝试通过Apache代理访问它,那么Apache将在接下来的60秒内返回503,无论您的后端现在是“up” . 请参阅ProxyPass上的apache文档,其中说明:

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

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

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

  • 41

    运行以下命令

    # /usr/sbin/setsebool httpd_can_network_connect 1
    

    要么

    # /usr/sbin/setsebool httpd_can_network_connect true
    

    然后重启httpd

    # service httpd restart
    
  • -2

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

    我正确关闭所以你必须手动杀死它们 . 这是一个link,有一些[可能的]帮助 .

    我最终在我的 /etc/init.d/ mongrel脚本中添加了一个"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>
    

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

  • 0

    尝试运行monit来监视Apache背后的混蛋,这样它就可以为你重启mongrel,如果它们死了或者对内存太饿了 . 如果出于任何原因,Apache仍然会感到困惑,你可能只需要优雅地重新启动apache就应该自行解决,但是99%的monit监视你的mongrels的情况应该再次避免这种情况发生 . 另一个选择是考虑Phusion Passenger .

  • 2

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

    netstat -tlpn
    

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

    sudo /etc/init.d/jenkins start
    

    它现在应该工作 . 希望能帮助到你 .

  • 1

    Fist,你必须安装 selinux :( SELinux代表安全增强型Linux . )

    apt-get install selinux
    

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

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

    注意:

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

    最后,重启apache!

  • 0

    为了使这个工作,我需要转换SELinux,然后添加尾部斜杠到“localhost:8000”行 .

    这是关闭SELinux的代码:

    echo 0 >/selinux/enforce
    

相关问题