Ошибки Nginx с Rails+Faye+Puma в Dokku Digital Ocean

Добрый день! Я хочу запустить приложение websocket с помощью драгоценного камня Faye, но возникает следующая проблема: когда я развертываю свое приложение на рабочем сервере, 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"

Я пробую Как запустить сервер faye в приложении rails, развернутом с помощью dokku? и Ошибка 502 Bad Шлюз на 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);
    });
});

Что я могу сделать? В среде разработки все работает нормально, а в продакшене только ошибки.


person Aleksandr_K    schedule 24.12.2014    source источник


Ответы (1)


Попробуйте настроить из этого списка https://gist.github.com/Bubelbub/0a942a0d51a3d329897d

В разделе сервера:

large_client_header_buffers 8 32k;

В локации Фэй:

 proxy_buffers 8 32k;
 proxy_buffer_size 64k;
person maksfromspb    schedule 11.03.2015