【问题标题】:Nginx errors with Rails+Faye+Puma on Dokku Digital OceanDokku Digital Ocean 上 Rails+Faye+Puma 的 Nginx 错误
【发布时间】:2015-02-22 21:13:17
【问题描述】:

美好的一天! 我想用 Faye gem 运行 websocket 应用程序,但是出现以下问题:当我在生产服务器上部署我的应用程序时,Ngix 无法接收 faye.js 并且无法连接到 faye 服务器。在 Nginx error.log 中我发现了下一个错误:

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" %>

并连接到faye服务器

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

我能做什么?在开发环境中一切正常,但在生产环境中只有错误。

【问题讨论】:

    标签: ruby-on-rails nginx digital-ocean puma dokku


    【解决方案1】:

    尝试从这个要点进行配置 https://gist.github.com/Bubelbub/0a942a0d51a3d329897d

    在服务器部分:

    large_client_header_buffers 8 32k;
    

    在faye位置:

     proxy_buffers 8 32k;
     proxy_buffer_size 64k;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-14
      • 2016-03-23
      • 2016-09-20
      • 1970-01-01
      • 2014-01-30
      • 1970-01-01
      • 2016-10-12
      • 1970-01-01
      相关资源
      最近更新 更多