Error 502 nginx + ruby ββon rails application
Application Details:
Rails 3.1.0
Ruby 1.9.2
unicorn 4.2.0
resque 1.20.0
Nginx /
1.0.14 redis 2.4.8
I'm using the active_admin gem to get a response for the whole 200 url,
but only one url gives 502 production errors.
rake routes:
admin_links GET /admin/links(.:format) {:action=>"index", :controller=>"admin/links"}
And his work on local (development).
localhost log: response code 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)
production log: 502 response
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 error log
2013/02/12 07:36:16 [error] 32401#0: *1948 upstream prematurely closed connection while reading response header from upstream
I don't know what's going on, can some of my friends help me.
source to share
You have a timeout problem.
Solution to the problem
HTTP / 1.1 502 Bad Gateway
Indicates that nginx has a problem with the stream configured above. http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#502
2013/02/12 07:36:16 [error] 32401 # 0: * 1948 prematurely closed upstream connection while reading upstream response header
The Nginx error log reports that Nginx was indeed able to connect to the configured upstream, but the process closed the connection before a response (completely) was received.
Your development environment:
Completed 200 OK in 15663ms
Apparently you need about 15 seconds to create a response on your development machine.
Unlike proxy_connect_timeout, this timeout will be caught by the server, which puts you in the connection pool, but doesn't reply to you beyond that. Be careful not to set this too low, as your proxy may take longer to respond to requests by (for example, when you serve a report page that takes a while to compute). However, you can have different settings in the location, which allows you to have a higher proxy_read_timeout for the location of the report page.
http://wiki.nginx.org/HttpProxyModule#proxy_read_timeout
On the nginx side proxy_read_timeout has a default of 60 seconds, so safe
I don't know how ruby ββ(on rails) works, check the error log - the timeout happens in that part of your stack
source to share