GitHub Documentation

Using HTTPS and WSS with an Apache proxy

  • Hi all,

    I'm running a NodeJS server on Ubuntu 18.04 behind an apache proxy.

    For anyone looking for the config for an apache proxy look no further :)
    After a lot of time spent searching for a solution, this is the solution I found.

    You'll need the following apache modules enabled:

    • ssl
    • proxy
    • proxy_http
    • proxy_html
    • proxy_wstunnel

    (or just run 'sudo a2enmod ssl proxy proxy_http proxy_html proxy_wstunnel')

    <VirtualHost *:80>
        #redirect all requests received from port 80 to the HTTPS variant (force ssl)
        RewriteEngine On
        RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
    <VirtualHost *:443>
        #enable SSL
        SSLEngine On
        SSLCertificateFile          /PATH/TO/CERT/FILE    (note: i'm using the fullchain.pem file which is generated using LetsEncrypt's certbot cli)
        SSLCertificateKeyFile       /PATH/TO/PRIVATE/KEY/FILE
        #setup the proxy to forward websocket requests properly (note: this proxy automatically converts the secure websocket (wss)
        #to a normal websocket and vice versa, so there's no need to change the colyseus library or the server for that matter)
        RewriteEngine On
        RewriteCond %{HTTP:UPGRADE} ^WebSocket$           [NC,OR]
        RewriteCond %{HTTP:CONNECTION} ^Upgrade$          [NC]
        RewriteRule .* ws://{REQUEST_URI}  [P,QSA,L]
        #setup the proxy to forward all https requests to http backend (also automatic conversion from https to http and vice versa)
        ProxyPass "/" ""
        ProxyPassReverse "/" ""

    I hope this post can be of any help :)


© 2021 Lucid Sight, Inc