Stephen Karger's solution above is the right one, you have to configure it to configure ELB to support proxies. Here are the AWS docs for doing just that: http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/enable-proxy-protocol.html . The docs are a bit complicated at first, so if you want, you can simply go to steps 3 and 4 in the Enable Proxy Protocol Using the AWS CLI section. These are the only necessary steps to enable the proxy channel. In addition, as Stephen suggested, you should make sure that your ELB uses TCP instead of http or https , since both of them will not work correctly with the ELB proxy implementation. I suggest moving your socket channel away from common ports such as 80 and 443, so that you can still support these standardized connections with their default behavior. Of course, this call depends entirely on how your application stack looks.
If this helps, you can use the npm wscat package to debug your website connections as follows:
$ npm install -g wscat $ wscat --connect 127.0.0.1
If the connection works locally, then this is probably your load balancer. However, if this does not happen, the problem with your socket host is almost certain.
In addition, a tool like nmap can help you open open ports. Good checklist for debugging:
npm install -g wscat
You can also use nmap from your server to detect open ports. install nmap on ubuntu, just sudo apt-get install nmap . on osx, brew install nmap
Here is the working configurator that I have, although at the moment it does not support ssl. In this configuration, I have port 80 loading the application for rails, port 81 feeds the socket through my elbow, and port 82 is open for internal socket connections. Hope this helps someone! Anyone who uses Rails, Unicorn and Faye for deployment should find this useful. :) happy hack!
# sets up deployed ruby on rails server upstream unicorn { server unix:/path/to/unicorn/unicorn.sock fail_timeout=0; } # sets up Faye socket upstream rack_upstream { server 127.0.0.1:9292; } # sets port 80 to proxy to rails app server { listen 80 default_server; keepalive_timeout 300; client_max_body_size 4G; root /path/to/rails/public; try_files $uri/index.html $uri.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 $scheme; proxy_redirect off; proxy_pass http://unicorn; proxy_read_timeout 300s; proxy_send_timeout 300s; } error_page 500 502 503 504 /500.html; location = /500.html { root /path/to/rails/public; } } # open 81 to load balancers (external socket connection) server { listen 81 proxy_protocol; server_name _; charset UTF-8; location / { proxy_pass http://rack_upstream; proxy_redirect off; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } } # open 82 to internal network (internal socket connections) server { listen 82; server_name _; charset UTF-8; location / { proxy_pass http://rack_upstream; proxy_redirect off; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } }
avocadojesus
source share