2011-09-26 133 views
0

我在Linode上運行Ubuntu 11.04,我試圖獲得Rails 3.1,Nginx 1.0.6,Passenger 3.0.9和PostgreSQL 8.4的設置和運行。我設法部署了我的應用程序,並且它看起來都很完美,但是在幾次成功的HTTP請求之後,服務器開始返回502網關錯誤。我使用了相同的設置在我的OS X開發機器上(PostgreSQL 8.4,Rails 3.1和WEBrick),它的工作原理非常完美。我在Nginx日誌中看到了它,它似乎是PostgreSQL問題。Rails,Nginx和PostgreSQL - 502網關錯誤

有誰知道這個問題可能是什麼?


2011/09/26 11:43:41 [error] 19694#0: *152 upstream prematurely closed connection while reading response header from upstream, client: <REDACTED>, server: localhost, request: "GET /news/new HTTP/1.0", upstream: "passenger:unix:/passenger_helper_server:", host: "<REDACTED>" 
[ pid=19978 thr=-609427238 file=utils.rb:176 time=2011-09-26 11:43:41.504 ]: *** Exception PGError in application (server closed the connection unexpectedly 
     This probably means the server terminated abnormally 
     before or while processing the request.** 
) (process 19978, thread #<Thread:0xb759c1b4>): 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:276:in `query' 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:276:in `clear_cache!' 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:275:in `each_value' 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:275:in `clear_cache!' 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:303:in `disconnect!' 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:202:in `disconnect_without_synchronization!' 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:201:in `each' 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:201:in `disconnect_without_synchronization!' 
     from /var/lib/gems/1.8/gems/activesupport-3.1.0/lib/active_support/core_ext/module/synchronization.rb:35:in `disconnect!' 
     from /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' 
     from /var/lib/gems/1.8/gems/activesupport-3.1.0/lib/active_support/core_ext/module/synchronization.rb:34:in `disconnect!' 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:395:in `clear_all_connections!' 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:395:in `each_value' 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:395:in `clear_all_connections!' 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in `__send__' 
     from /var/lib/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in `clear_all_connections!' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/utils.rb:398:in `before_handling_requests' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/rack/application_spawner.rb:204:in `start_request_handler' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/rack/application_spawner.rb:170:in `send' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/rack/application_spawner.rb:170:in `handle_spawn_application' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/utils.rb:479:in `safe_fork' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/rack/application_spawner.rb:165:in `handle_spawn_application' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `__send__' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:180:in `start' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/rack/application_spawner.rb:128:in `start' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:253:in `spawn_rack_application' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:246:in `spawn_rack_application' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `__send__' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop' 
     from /opt/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously' 
     from /opt/passenger-3.0.9/helper-scripts/passenger-spawn-server:99 

---------- 

謝謝!

+0

我似乎已經通過在config/environments/production.rb中更改config.action_controller.perform_caching = false來解決這個問題,但我仍然無法弄清楚爲什麼緩存會導致Postgres錯誤,並且它不是一個真正可行的選項在生產模式下關閉緩存。 – rsl

回答

1

在這種情況下寫入日誌PostgreSQL的是什麼?必須有一些理由來關閉連接 - 可能是舊版本的PostgreSQL?

+0

我檢查了日誌,我能看到的唯一錯誤是: 2011-09-25 16:43:50 BST日誌:不完整的啓動數據包 2011-09-25 18:31:53 BST LOG:意外的EOF在客戶端連接 2011-09-26 11:39:10 BST日誌:客戶端連接上意外的EOF 2011-09-26 11:39:26 BST日誌:客戶端連接上意外的EOF 2011-09-26 13:00 :42 BST日誌:不完整的啓動數據包。 我不完全確定爲什麼數據庫客戶端例如在這種情況下,Rails不會發送完整的數據流,這可能與Nginx的超時設置有關嗎? – rsl

+0

對不起太遲了......你有哪個版本的Postgresql,哪個版本是Postgresql客戶端庫? –