Skip to content

Instantly share code, notes, and snippets.

@iacchus
Last active September 21, 2022 18:45
Show Gist options
  • Star 30 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save iacchus/954e0787d6893c5ab8e1 to your computer and use it in GitHub Desktop.
Save iacchus/954e0787d6893c5ab8e1 to your computer and use it in GitHub Desktop.
Set reverse proxy websockets in Apache 2.4 using socket.io 1.0. Needs mod_rewrite module, this version uses SSL. As seen here https://serverfault.com/questions/616370/configuring-apache-2-4-mod-proxy-wstunnel-for-socket-io-1-0
<VirtualHost *:80>
ServerName forum.example.com
Redirect permanent / https://forum.example.com
</VirtualHost>
<VirtualHost *:443>
ServerName forum.example.com
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
SSLCertificateFile /etc/apache2/ssl/example-com/forum.ssl.crt
SSLCertificateKeyFile /etc/apache2/ssl/example-com/private.key
SSLCertificateChainFile /etc/apache2/ssl/example-com/sub.class1.server.ca.pem
# ServerAdmin webmaster@localhost
<Proxy *>
Require all granted
</Proxy>
ProxyRequests off
ProxyVia on
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:4567/$1 [P,L]
ProxyPass /socket.io http://localhost:4567/socket.io
ProxyPassReverse /socket.io http://localhost:4567/socket.io
<Location />
ProxyPass http://127.0.0.1:4567/
ProxyPassReverse http://127.0.0.1:4567/
</Location>
ErrorLog /home/username/logs/apache/forum-error.log
CustomLog /home/username/logs/apache/forum-access.log combined
</VirtualHost>
@osiztechnologies
Copy link

We have tried this conf. but its not working. Kindly advise us.

@ak2766
Copy link

ak2766 commented Jun 15, 2020

Thanks so iacchus - these instructions are the only ones that worked for me. All others just lead me down a rabbit hole that was never ending.

Only question - I noticed that Apache takes a long long time to complete a restart - is this expected? I also noticed that If I refresh (or close the page) when Apache is hung on restart, it completes the restart immediately. What can be done to ensure it restarts immediately?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment