Customizing ActionCable with Elasticache for Rails 5.0 on an Elastic Beanstalk

I created a Rails 5.0 application with Elastic Beanstalk on Amazon web services, and I was able to successfully create a website with a functioning database. The only problem is that I need an ActionCable to run my application, and it is very difficult for me to configure Elasticache and successfully connect the rails application to the Elasticache cluster.

Many people told me that the load balancer in Elastic Beanstalk does not allow you to communicate with the Elasticache cluster, and I could not find any documentation on how to integrate Redis into the elastic beanstalk in order to configure ActionCable correctly.

Do you guys know a step-by-step detailed approach to successfully setting up ActionCable on Elastic Beanstalk Rails 5.0 using Elasticache?

+4
source share
1 answer

The most important thing is to change the loadbalancer to a TCP and SSL user instead of HTTP and HTTPS. You also need to configure nginx to send update headers to the location / cable.

Try adding this file (nginx.config) to the .ebextensions folder:

files:
  /etc/nginx/conf.d/proxy.conf:
    content: |
      client_max_body_size 500M;
      server_names_hash_bucket_size 128;

      upstream backend {
        server unix:///var/run/puma/my_app.sock;
      }

      server {
        listen 80;

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

        server_name *.cmgresearch.net;

        large_client_header_buffers 8 32k;

        location / {
          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;
          proxy_set_header X-NginX-Proxy true;

          proxy_buffers 8 32k;
          proxy_buffer_size 64k;

          proxy_pass http://backend;
          proxy_redirect off;

          location /assets {
            root /var/app/current/public;
          }

          # enables WS support
          location /cable {
            proxy_pass http://backend;
            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;
          }
        }
      }


container_commands:
  01restart_nginx:
    command: "service nginx restart"

See https://blog.cmgresearch.com/2017/05/11/step-7-action-cable-on-elastic-beanstalk.html

0
source

Source: https://habr.com/ru/post/1672609/


All Articles