mysql - 502 错误 nginx + ruby​​ on rails 应用程序

标签 mysql ruby-on-rails-3 nginx activeadmin

申请详情:
导轨 3.1.0
ruby 1.9.2
unicorn 4.2.0
重新请求 1.20.0
nginx/1.0.14
雷迪斯 2.4.8

我正在使用 active_admin gem,所有 URL 都获得响应 200,
但只有一个 URL 在生产时出现 502 错误。

佣金路线:

admin_links GET        /admin/links(.:format)                                            {:action=>"index", :controller=>"admin/links"}

它致力于本地(开发)。

本地主机日志:响应代码 200

    Started GET "/admin/links" for 127.0.0.1 at 2013-02-12 11:05:21 +0530
        Processing by Admin::LinksController#index as */*
        Parameters: {"link"=>{}}
    Geokit is using the domain: localhost
        AdminUser Load (0.2ms)  SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 3 LIMIT 1
         (0.1ms)  SELECT 1 FROM `links` LIMIT 1 OFFSET 0
         (0.1ms)  SELECT COUNT(*) FROM `links` 
         (0.2ms)  SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM `links` LIMIT 10 OFFSET 0) subquery_for_count 
        CACHE (0.0ms)  SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM `links` LIMIT 10 OFFSET 0) subquery_for_count 
        Link Load (0.6ms)  SELECT `links`.* FROM `links` ORDER BY `links`.`id` desc LIMIT 10 OFFSET 0
        Link Load (6677.2ms)  SELECT `links`.* FROM `links` 
    Rendered /usr/local/rvm/gems/ruby-1.9.2-head/gems/activeadmin-0.4.2/app/views/active_admin/resource/index.html.arb (14919.0ms)
    Completed 200 OK in 15663ms (Views: 8835.0ms | ActiveRecord: 6682.8ms | Solr: 0.0ms)

生产日志:502响应

    Started GET "/admin/links" for 103.9.12.66 at 2013-02-12 05:25:37 +0000
        Processing by Admin::LinksController#index as */*
        Parameters: {"link"=>{}}

NGinx 错误日志

2013/02/12 07:36:16 [error] 32401#0: *1948 upstream prematurely closed connection while reading response header from upstream

不知道怎么回事,有没有哥们帮帮我。

最佳答案

您遇到了超时问题。

解决它

HTTP/1.1 502 Bad Gateway

表示,nginx 在与其配置的上游通信时出现问题。 http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#502

2013/02/12 07:36:16 [error] 32401#0: *1948 upstream prematurely closed connection while reading response header from upstream

Nginx 错误日志告诉您 Nginx 实际上能够连接到配置的上游,但进程在(完全)收到答案之前关闭了连接。

您的开发环境:

Completed 200 OK in 15663ms

显然,您需要大约 15 秒才能在您的开发机器上生成响应。

In contrast to proxy_connect_timeout, this timeout will catch a server that puts you in it's connection pool but does not respond to you with anything beyond that. Be careful though not to set this too low, as your proxy server might take a longer time to respond to requests on purpose (e.g. when serving you a report page that takes some time to compute). You are able though to have a different setting per location, which enables you to have a higher proxy_read_timeout for the report page's location.

http://wiki.nginx.org/HttpProxyModule#proxy_read_timeout

在 nginx 端,proxy_read_timeout 默认为 60 秒,所以这是安全的

我不知道 ruby​​ (on rails) 是如何工作的,检查错误日志 - 超时发生在你的堆栈部分

关于mysql - 502 错误 nginx + ruby​​ on rails 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14825304/

相关文章:

mysql - 将图像存储在现有表列中并使用 laravel 4 显示它

php - mysql 中的 rowCount 处理某些带有值的列

javascript - 使用 Rails 从数字字段进行 jQuery ajax 调用不起作用

ruby-on-rails - 无法删除记录,用户

mysql - 15分钟后切换mysql二进制日志

mysql - 如何用grails更新MySql表中的数据?

ruby-on-rails - 渲染Liquid模板时"Template is missing"

html - NGINX动态位置创建动态og :image

javascript - net::ERR_CONNECTION_CLOSED 错误在 Chrome 与 HTTP2.0 + Nginx

nginx - 在 Tornado v4+ 下,WebSocket 连接被 403 拒绝