2016-03-28 21 views
9

私は最近、Rails4から5.0.0.beta3に私のレールプロジェクトを切り替えて、すばらしいActionCableを使用しました。NginxとUnicornを使用してProductionCableをプロダクションで設定するには?

私のActionCableサーバは、ユニコーン内で動作します。開発ではすべて正常に動作します。生産では、私は

Started GET "/cable" for xxx.xxx.xxx.xxx at 2016-03-28 18:06:38 +0300 
Started GET "/cable/" [WebSocket] for xxx.xxx.xxx.xxx at 2016-03-28 18:06 
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) 
Registered connection (189772ff-6229-48f1-ae7f-d9a96ad3a6c3) 
Finished "/cable/" [WebSocket] for xxx.xxx.xxx.xxx at 2016-03-28 18:06:35 

を持っており、このメッセージは、ループ内で何度も何度も繰り返されます。

私はこれを処理するためにstackoverflowで多くのオプションを試しましたが、何も役立ちません。 私のnginxの設定ファイル:

upstream unicorn { 
    server unix:/tmp/unicorn.my_app.sock fail_timeout=0; 
} 

server { 
    server_name www.my_app.com; 
    return 301 $scheme://my_app.com$request_uri; 
} 

server { 
    listen 80 default deferred; 
    server_name my_app.com; 
    root /var/www/my_app/current/public; 

    location ^~ /assets/ { 
    gzip_static on; 
    expires max; 
    add_header Cache-Control public; 
    } 

    try_files $uri/index.html $uri @unicorn; 
    location @unicorn { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
    proxy_pass http://unicorn; 
    } 

    location /cable { 
    proxy_pass http://unicorn/cable; 
    proxy_http_version 1.1; 
    proxy_set_header Upgrade websocket; 
    proxy_set_header Connection Upgrade; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    } 

    error_page 500 502 503 504 /500.html; 
    keepalive_timeout 5; 
} 

要求は私が一時的に初期化子でこのコードを使用しまし許可されていることを確認するために: ActionCable.server.config.disable_request_forgery_protection = true

マイcable.coffeeファイル

@App ||= {} 
App.cable = ActionCable.createConsumer "/cable" 

config/cable.ymlファイルには、

production: 
adapter: redis 
url: redis://localhost:6379/1 

私はこの質問にあまり慣れていないので、どんな助けも素晴らしいでしょう。

+0

あなたのルートに 'Mount ActionCable.server => '/ cable''がありますか? – siegy22

+0

@yzalavinこれを解決できましたか?私は同じ問題を抱えています。 –

+0

@R_G私も同じ問題を抱えています。問題を見つけることができましたか?私がユニコーンをデバッグしたものから、クライアントにpingを送信できないので、クライアントは再接続しようとしています。したがって、ループ内のconnect文。他の方向の流れがうまくいかない理由がわからない – sethi

答えて

1

rack-timeoutを実装しました。正しいタイムアウトを設定すると私の問題が解決しました。次のようにこれらの変数を設定するための適切な方法はconfig.ru使用文である:

use Rack::Timeout, service_timeout: 5 
0

これは私が私のウェブサイトのために使用設定され、それが正常に動作しているようだ(Railsの5 + nginxの+ユニコーン+カピストラーノ)。スニペットに表示されるものはh5bp/server-configs-nginxですが、設定がうまくいかない理由が考えられます。

upstream example_app { 
    server unix:/home/username/www/example.com/current/tmp/sockets/unicorn.example.com.sock fail_timeout=0; 
} 

server { 
    listen 80; 
    server_name example.com www.example.com; 

    return 301 https://example.com$request_uri; 
} 

server { 
    listen 443 ssl; 
    server_name www.example.com; 

    include h5bp/directive-only/ssl.conf; 
    ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; 

    return 301 https://example.com$request_uri; 
} 

server { 
    listen 443 ssl; 
    server_name example.com; 

    include h5bp/directive-only/ssl.conf; 
    ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; 

    root /home/username/www/example.com/current/public; 

    # Set maximum request body size for uploads 
    client_max_body_size 25m; 

    try_files $uri/index.html $uri @unicorn; 
    location @unicorn { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_set_header X-Forwarded-Proto https; 
    proxy_redirect off; 
    proxy_pass http://example_app; 
    } 

    location /cable { 
    proxy_pass http://example_app; 
    proxy_http_version 1.1; 
    proxy_set_header Upgrade websocket; 
    proxy_set_header Connection Upgrade; 

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-Proto https; 
    proxy_redirect off; 
    } 

    access_log /var/log/nginx/example.com/access.log; 
    error_log /var/log/nginx/example.com/error.log; 

    charset utf-8; 
    server_tokens off; 

    error_page 404 /404.html; 

    include h5bp/basic.conf; 
} 

cable.yml

production: 
    adapter: redis 
    url: redis://localhost:6379/1 

cable.js

location /cableセクションで
//= require action_cable 
//= require_self 
//= require_tree ./channels 

(function() { 
    this.App || (this.App = {}); 

    App.cable = ActionCable.createConsumer(); 

}).call(this); 
3

proxy_set_header Host $http_host;

があるべき行を追加する必要があります。

location /cable { 
    proxy_pass http://unicorn/cable; 
    proxy_http_version 1.1; 
    proxy_set_header Upgrade websocket; 
    proxy_set_header Connection Upgrade; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    } 
+0

これは私のために働いた:) –

関連する問題