Skip to content

Instantly share code, notes, and snippets.

@rielcfb
Last active September 22, 2022 11:05
Show Gist options
  • Select an option

  • Save rielcfb/d22914c83df4f26b0fe87122943e28c6 to your computer and use it in GitHub Desktop.

Select an option

Save rielcfb/d22914c83df4f26b0fe87122943e28c6 to your computer and use it in GitHub Desktop.

Revisions

  1. rielcfb revised this gist Sep 22, 2022. No changes.
  2. rielcfb revised this gist Sep 22, 2022. 1 changed file with 70 additions and 1 deletion.
    71 changes: 70 additions & 1 deletion Httpd-Apache-2.4.6-VHost-Config-Reverse-Proxy.conf
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,73 @@
    # Httpd Apache/2.4.6 VHost Config Reverse Proxy Node.js App RHEL CENTOS 7
    # Websocket / ws / wss / socket.io
    # Solved after errors:
    # connection_error
    # connection_error: code 3 Bad Request
    # engine invalid transport upgrade
    # engine error handshaking to transport "websocket"
    # socket.io-client: websocket error
    # socket.io-client: failed wss connection
    # socket.io-client: failed connection using transport websocket / ws / wss

    # File: /etc/httpd/conf.d/io.example.com.conf
    # For port 80 / http
    <VirtualHost *:80>
    ServerName io.example.com

    # ----- Optional -----------------------------------------------------------
    # <Proxy *>
    # Require all granted
    # </Proxy>
    # --------------------------------------------------------------------------

    # ----- Worked Simple -------------------------------------------------------
    # ProxyPreserveHost on
    ProxyRequests on

    ProxyPass /socket.io/ ws://localhost:3000/socket.io/
    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/
    # ----------------------------------------------------------------------------

    # ----- this is general options from apache / socket.io documentation --------
    # RewriteEngine on
    # RewriteCond ${HTTP:Upgrade} websocket [NC]
    # RewriteCond ${HTTP:Connection} upgrade [NC]
    # RewriteRule ^/?(.*) ws://localhost:1202/$1 [P,L]

    # ProxyTimeout 3
    # -----------------------------------------------------------------------------

    # ----- Redirect permanent to https -------------------------------------------
    # RewriteCond %{SERVER_NAME} =io.example.com
    # RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    # -----------------------------------------------------------------------------

    </VirtualHost>

    # File: /etc/httpd/conf.d/io.example.com-le-ssl.conf
    # For Port 443 / https
    <VirtualHost *:443>
    ServerName io.example.com:443

    SSLEngine on
    SSLProxyEngine on

    # LetsEncrypt SSL
    SSLCertificateFile /etc/letsencrypt/live/io.example.com/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/io.example.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateChainFile /etc/letsencrypt/live/io.example.com/chain.pem

    <Proxy *>
    Require all granted
    </Proxy>

    ProxyPreserveHost on
    ProxyRequest on

    ProxyPassMatch ^/socket.io/(.*) ws://localhost:3000/socket.io/$1
    # Or
    # ProxyPass /socket.io/ ws://localhost:3000/socket.io/
    ProxyPass / http://localhost:3000/
    ProxyReverse / http://localhost:3000/
    </VirtualHost>
  3. rielcfb created this gist Sep 22, 2022.
    4 changes: 4 additions & 0 deletions Httpd-Apache-2.4.6-VHost-Config-Reverse-Proxy.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    # Httpd Apache/2.4.6 VHost Config Reverse Proxy Node.js App RHEL CENTOS 7
    # Websocket / ws / wss / socket.io
    # Solved after errors:
    # connection_error