Skip to content

Instantly share code, notes, and snippets.

@skorotkiewicz
Created August 21, 2019 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skorotkiewicz/28ce7d2422508fa38d843d64342050d6 to your computer and use it in GitHub Desktop.
Save skorotkiewicz/28ce7d2422508fa38d843d64342050d6 to your computer and use it in GitHub Desktop.
Socket.io via Apache Reverse Proxy
<VirtualHost *:80>
ServerName example.com
ServerAlias example.com www.example.com
ServerAdmin admin@example.com
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://example.com/$1 [NC,R,L]
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias example.com www.example.com
ServerAdmin admin@example.com
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://127.0.0.1:3020/$1 [P,L]
ProxyPass /socket.io http://127.0.0.1:3020/socket.io
ProxyPassReverse /socket.io http://127.0.0.1:3020/socket.io
<Location />
ProxyPass http://127.0.0.1:3000/
ProxyPassReverse http://127.0.0.1:3000/
</Location>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/example.com/fullchain.pem
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment