2014-12-24 60 views
0

美好的一天! 我想運行與Faye寶石websocket應用程序,但會發生以下問題:當我在生產服務器上部署我的應用程序時,Ngix無法接收faye.js並無法連接到faye服務器。在Nginx的error.log中我發現旁邊的錯誤:Dokku Digital Ocean上的Rails + Faye + Puma的Nginx錯誤

2014/12/24 15:44:39 [error] upstream prematurely closed connection while reading response header from upstream, client: 46.0.121.23, server: example.com, request: "GET /faye HTTP/1.1", upstream: "http://127.0.0.1:9292/faye", host: "example.com" 

2014/12/24 15:44:39 [error] *1 connect() failed (111: Connection refused) while connecting to upstream, client: 46.0.121.23, server: example.com, request: "GET /faye HTTP/1.1", upstream: "http://127.0.0.1:9292/faye", host: "example.com" 

我嘗試How to start faye server on a rails app deployed using dokku?Error 502 Bad Gateway on NGINX + rails + dokku答案,但它不能幫助我。

我Procfile是

web: bundle exec rails s Puma -p 5000 
faye: bundle exec rackup s Puma faye.ru 

我faye.ru是

require 'faye' 
require File.expand_path('../config/initializers/faye_token.rb', __FILE__) 

class ServerAuth 
    def incoming(message, callback) 
    if message['channel'] !~ %r{^/meta/} 
     if message['ext']['auth_token'] != FAYE_TOKEN 
     message['error'] = 'Invalid authentication token.' 
     end 
    end 
    callback.call(message) 
    end 
end 
faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 0) 
faye_server.add_extension(ServerAuth.new) 
run faye_server 

我的nginx.conf是:

upstream example.com { server 127.0.0.1:49169; } 
server { 
    listen  [::]:80; 
    listen  80; 
    server_name example.com; 
    location /{ 
    proxy_pass http://example.com; 
    proxy_http_version 1.1; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
    proxy_set_header Host $http_host; 
    proxy_set_header X-Forwarded-Proto $scheme; 
    proxy_set_header X-Forwarded-For $remote_addr; 
    proxy_set_header X-Forwarded-Port $server_port; 
    proxy_set_header X-Request-Start $msec; 
    } 
    location /faye { 
    proxy_redirect  off; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
    proxy_http_version 1.1; 
    proxy_buffering off; 
    proxy_cache_bypass $http_pragma $http_authorization; 
    proxy_no_cache  $http_pragma $http_authorization; 
    proxy_pass http://localhost:9292; 
    } 
} 

我的應用程序得到faye.js未來:

<%= javascript_include_tag "http://example.com/faye.js" %> 

,並連接到服務器王菲

$(function() { 
    var faye = new Faye.Client('http://example.com/faye'); 
    faye.subscribe('/comments/new', function (data) { 
     eval(data); 
    }); 
}); 

我能做些什麼?在開發環境中,所有工作都很好,但在生產中只有錯誤。

回答

相關問題