We are attempting to deploy DHH\'s simple Rails 5 chat example to a single, self contained EC2 instance on AWS. Code is available here: https://github.com/HectorPerez/chat-i
To run the websocket chat example on a single instance Elastic Beanstalk deployment in AWS, you will need to add the following Nginx proxy configuration ( Note: replace "env1.t3tiiauce6.us-west-2.elasticbeanstalk.com" with your sitename ):
.ebextensions/nginx_proxy.config
files:
"/etc/nginx/conf.d/websockets.conf" :
content: |
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 env1.t3tiiauce6.us-west-2.elasticbeanstalk.com
# prevents 502 bad gateway error
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;
# prevents 502 bad gateway error
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 $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
}
container_commands:
01restart_nginx:
command: "nginx -t && service nginx reload"
`