How to use SSL HTML and Websockets on Apache?

Viewed 30

I have only used Apache HTML on my backend and implemented my app using HTML/PHP requests so far. Now I want to implement a socket connection. For this, I am currently trying to set up the socket module on my Apache web server. I tried these steps. Reverse Proxy. However, after adding ProxyPass on the VirtualHost :443, I can no longer access my HTML pages.

503 Service Unavailable - The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Is it possible to still access the HTML/PHP pages despite the socket module? Do i have to create a new VirtualHost with a different Port, e.g. the Websocket Port but how can i make the handshake? My apache2/sites-available/conf looks like this:

    <VirtualHost *:80>
        ServerName ***
        
        <IfModule mod_ssl.c>
                Redirect / https://***
        </IfModule>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/***

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName ***
        ServerAdmin webmaster@localhost 
        DocumentRoot /var/www/***

        <Directory /var/www>
#               Options -Indexes +FollowSymLinks
#               AllowOverride none
#               Order allow,deny
#               allow from all
        </Directory>    

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        RewriteEngine on
        RewriteCond ${HTTP:Upgrade} websocket [NC]
        RewriteCond ${HTTP:Connection} upgrade [NC]
        RewriteRule .* "wss:/localhost:12123/$1" [P,L]

        ProxyPass / https://localhost:12123/  #Here is the problem
        ProxyPassReverse / https://localhost:12123/
        ProxyRequests off

        SSLEngine On
        SSLCertificateFile /etc/letsencrypt/live/***/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/***/privkey.pem
        SSLCertificateChainFile /etc/letsencrypt/live/***/chain.pem
</VirtualHost>
</IfModule>
0 Answers
Related