たれみみマンデー

AWS、Nginx、Unicorn、RailsでActionCableを使用する

Redisは使いません。

 

AWS上 /etc/nginx/conf.d/*******.conf ↓

location /cable {

 proxy_pass http://app_server(upstream *****と同じやつ)/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;

}

 

config/routes.rb ↓

mount ActionCable.server => '/cable'

 

config/cable.yml ↓

production:

  adapter: async

 

config/environments/production.rb ↓

以下追加

ActionCable.server.config.disable_request_forgery_protection = true

config.action_cable.url = 'ws://***ドメインor IP***/cable'

config.action_cable.allowed_request_origins = [ 'http://***ドメインor IP***' ]   

   

たれみみ

@taremimi_7