To enable both HTTP and WebSocket traffic for Node-Red through your Apache reverse proxy, you need to make some modifications to your Apache configuration. Here's what you can try:
- Enable WebSocket proxying by adding the following lines to the VirtualHost section for Node-Red:
<Location /ws>
ProxyPass ws://localhost:1880/ws
ProxyPassReverse ws://localhost:1880/ws
</Location>
This tells Apache to proxy all WebSocket traffic to Node-Red.
- Modify the existing ProxyPass and ProxyPassReverse directives to exclude the WebSocket endpoint. Add the following line after the tag from the previous step:
ProxyPassMatch "^/(?!ws)(.*)" "http://localhost:1880/$1"
This tells Apache to proxy all HTTP traffic to Node-Red except for the WebSocket endpoint.
The modified VirtualHost section should look like this:
<VirtualHost *:443>
ServerName nr.domain.com
SSLEngine On
<Location /ws>
ProxyPass ws://localhost:1880/ws
ProxyPassReverse ws://localhost:1880/ws
</Location>
<Location />
ProxyPassMatch "^/(?!ws)(.*)" "http://localhost:1880/$1"
ProxyPassReverse http://localhost:1880/
</Location>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/nr.domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/nr.domain.com/privkey.pem
</VirtualHost>
Restart Apache for the changes to take effect:
sudo systemctl restart apache2
With these changes, both HTTP and WebSocket traffic should be proxied correctly to Node-Red through your Apache reverse proxy.