Category Archives: actioncable

Websocket connection error Actioncable rails5 apache aws

Action cable not working in AWS with ssl. Getting the following error. It's working fine in local environment.

WebSocket connection to 'wss://www.example.net/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

Here's my apache configuration.

<VirtualHost *:80>
ServerName    example.net
DocumentRoot /home/ubuntu/mydomain/public
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
<Proxy balancer://unicornservers>
Allow from any
BalancerMember http://127.0.0.1:3000
</Proxy>
<Proxy balancer://thinservers>
Allow from any
BalancerMember http://127.0.0.1:9292
</Proxy>
ProxyPass /faye http://127.0.0.1:9292
ProxyPassReverse /faye http://127.0.0.1:9292
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/home/ubuntu/mydomain/public">
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName    example.net
DocumentRoot /home/ubuntu/mydomainco/public
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
RequestHeader set X-Forwarded-Proto "https"
RewriteCond %{HTTP_HOST} ^mydomain/.net$ [NC]
RewriteRule ^ https://www.example.net%{REQUEST_URI} [R=301,L]
<Proxy balancer://unicornservers>
Allow from any
BalancerMember http://127.0.0.1:3000
</Proxy>
<Proxy balancer://thinservers>
Allow from any
BalancerMember http://127.0.0.1:3000
</Proxy>
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule "/cable" ws://127.0.0.1:3000/cable [P]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /home/ubuntu/ssl/31755a8ebd042758.crt
SSLCertificateKeyFile /home/ubuntu/ssl/mydomain.key
SSLCertificateChainFile /home/ubuntu/ssl/gd_bundle-g2-g1.crt
<Directory "/home/ubuntu/mydomainco/public">
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>    

Websocket connection error Actioncable rails5 apache aws

Action cable not working in AWS with ssl. Getting the following error. It's working fine in local environment.

WebSocket connection to 'wss://www.example.net/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

Here's my apache configuration.

<VirtualHost *:80>
ServerName    example.net
DocumentRoot /home/ubuntu/mydomain/public
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
<Proxy balancer://unicornservers>
Allow from any
BalancerMember http://127.0.0.1:3000
</Proxy>
<Proxy balancer://thinservers>
Allow from any
BalancerMember http://127.0.0.1:9292
</Proxy>
ProxyPass /faye http://127.0.0.1:9292
ProxyPassReverse /faye http://127.0.0.1:9292
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/home/ubuntu/mydomain/public">
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName    example.net
DocumentRoot /home/ubuntu/mydomainco/public
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
RequestHeader set X-Forwarded-Proto "https"
RewriteCond %{HTTP_HOST} ^mydomain/.net$ [NC]
RewriteRule ^ https://www.example.net%{REQUEST_URI} [R=301,L]
<Proxy balancer://unicornservers>
Allow from any
BalancerMember http://127.0.0.1:3000
</Proxy>
<Proxy balancer://thinservers>
Allow from any
BalancerMember http://127.0.0.1:3000
</Proxy>
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule "/cable" ws://127.0.0.1:3000/cable [P]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /home/ubuntu/ssl/31755a8ebd042758.crt
SSLCertificateKeyFile /home/ubuntu/ssl/mydomain.key
SSLCertificateChainFile /home/ubuntu/ssl/gd_bundle-g2-g1.crt
<Directory "/home/ubuntu/mydomainco/public">
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>