Score:1

Websocket with Apache 2.4.52 and Ubuntu

in flag

I am trying to follow tutorial located here for messaging system using RatChet PHP https://www.twilio.com/blog/create-php-websocket-server-build-real-time-even-driven-application I have my domain called example.com which have normal html page and need to serve it as normal website. for messaging system, I want port called 8445

so I have installed apache2 on ubuntu 22.04 installed lets encrypt ssl site is working fine

Now I want setup websocket server so opened tcp port 8445 in firewall

enabled apache modules

a2enmod proxy a2enmod proxy_http a2enmod proxy_wstunnel

I have replaced my original domain with example.com

my conf file is like example.com.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog /var/www/example.com/public_html/logs/error.log
    CustomLog /var/www/example.com/public_html/logs/access.log combined

        ProxyRequests Off
        ProxyPass / https://example.com:8445/
        ProxyPassReverse / https://example.com:8445/

</VirtualHost>

and

example.com-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
    SSLEngine On
    SSLProxyEngine On
    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog /var/www/example.com/public_html/logs/error.log
    CustomLog /var/www/example.com/public_html/logs/access.log combined

        ProxyRequests Off
        ProxyPass / wss://example.com:8445/
        ProxyPassReverse / https://example.com:8445/


Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
<Location />
        ProxyPassReverse /

        Options FollowSymLinks
        Require all granted
    </Location>

</VirtualHost>
</IfModule>

When I try to connect, I am getting 503 error and apache log is saying like

[proxy_http:error] [pid 20090] [client 49.34.X.X:55961] AH01114: HTTP: failed to make connection to backend: example.com [Sat Dec 03 16:47:04.378489 2022] [proxy:error] [pid 20091] (111)Connection refused: AH00957: wss: attempt to connect to 45.33.X.X:8445 (example.com) failed

Let me know if anyone here can help me for solve issue.

Thanks!

vidarlo avatar
ar flag
You get connection refused for example.com:8445. Is anything listening to example.com:8445? Is your daemon perhaps listening on 127.0.0.1?
Score:0
ee flag

It looks like the issue is that the Apache proxy is failing to connect to the backend server on port 8445. There are a few things you can check to troubleshoot this:

Verify that the websocket server is running and listening on port 8445. You can use the netstat command to check this:

sudo netstat -tlnp | grep 8445

If the websocket server is running, you should see a line that looks like this:

tcp        0      0 0.0.0.0:8445            0.0.0.0:*               LISTEN      <websocket server PID>/websocket

Verify that there are no firewalls or security groups blocking traffic to port 8445. You can check this by trying to connect to the websocket server from the server itself:

telnet localhost 8445

If the connection is successful, you should see a blank screen. If the connection is refused, there may be a firewall or security group blocking traffic.

Verify that the websocket server is configured to accept connections from the Apache proxy. Depending on the websocket server you are using, this may involve setting a specific IP address or hostname to listen on, or configuring access control lists (ACLs) to allow connections from the Apache server's IP address.

Check the logs of the websocket server to see if there are any error messages indicating why the connection is being refused.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.