Fury
Fury

Reputation: 4776

Configure Ratchet and EC2 and AWS Load Balancer throws WebSocket connection to 'wss://chat.domain.com:8080/' failed

I have built a Websocket on Ubuntu 20.04 (LAMP) stack using Ratchet.

I followed this article https://www.twilio.com/blog/create-php-websocket-server-build-real-time-even-driven-application to build the websocket.

I Followed this article Does an Application Load Balancer support WebSockets? to configure my webserver.

  1. Configured Security Group - Inbound rules TCP 8080
  2. Configured Load balancer
  3. Created Target group (TCP) for port 8080

enter image description here

  1. Enabled Stickyness (1 hour)
  2. SSL is configured and created in AWS Certificate Manager

enter image description here

  1. Apache configuration

    <VirtualHost *:80>
        ServerName chat.domain.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/websites/chat.domain.com/public
           <Directory /var/www/websites/chat.domain.com/public/>
               Options Indexes FollowSymLinks MultiViews
               AllowOverride All
               Require all granted
           </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/chat.domain.com/error.log
        CustomLog ${APACHE_LOG_DIR}/chat.domain.com/access.log combined
    </VirtualHost>
    
    <VirtualHost *:443>
        ServerName chat.domain.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/websites/chat.domain.com/public
           <Directory /var/www/websites/chat.domain.com/public/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
            </Directory>
    
        ProxyPass / https://chat.domain.com:8080/
        ProxyPassReverse / https://chat.domain.com:8080/
        <Location "/">
            ProxyPass "wss://chat.domain.com:8080/"
        </Location>
    
    
        ErrorLog ${APACHE_LOG_DIR}/chat.domain.com/error.log
        CustomLog ${APACHE_LOG_DIR}/chat.domain.com/access.log combined
    </VirtualHost>
    

Every thing is in place and running but I get

WebSocket connection to 'wss://chat.domain.com:8080/' failed:

Here is my chrome inspect

enter image description here

I have even tried to Open traffic to ALL ports (Inbond) just to check the security group but still getting the same error.

I doubt the problem is configuring Load Balancer, Security Group and Target group?

Any help or suggestion?

Upvotes: 1

Views: 343

Answers (1)

Fury
Fury

Reputation: 4776

Finally I found the solution. The port 8080 should have been added to firewall and I had to create a new target group for port 8080 which then I had to create a load balancer with port http:8080 and point to the target group.

Upvotes: 0

Related Questions