WebSocket reverse proxy with Apache 2.4

To allow access to my local smartMeterLogger I setup a virtual host energie.wasietsmet.nl.

This means setting up a reverse proxy for the websocket running on the smartMeterLogger.
First thing to do is to enable proxy_wstunnel with a2enmod.
Then set up the virtual host. See below how to.
Don’t forget to reload the settings in Apache2!

<VirtualHost *:80>
ServerName energie.wasietsmet.nl

  ProxyRequests Off
 
  ProxyPreserveHost On
 
  ProxyPass / "http://192.168.0.107/"
  ProxyPassReverse / "http://192.168.0.107/"
        
  RewriteEngine on
  RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
  RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
  RewriteRule .* ws://192.168.0.107%{REQUEST_URI} [P]

SetEnvIf Request_URI "^/events" dontlog
SetEnvIf Request_URI "^/raw" dontlog
 
CustomLog "|/usr/bin/rotatelogs /var/www/energie.wasietsmet.nl/log/access%d-%m-%Y 86400" vhost_combined env=!dontlog
ErrorLog "|/usr/bin/rotatelogs /var/www/energie.wasietsmet.nl/log/error%d-%m-%Y 86400"
</VirtualHost>

Links:

http://aripratech.com/reverse-proxy-websockets-with-apache-httpd-server/

Install Pi-hole on Volumio.

  • Install Volumio the normal way.
  • Set Volumio to accept ssh connections in the developer settings.
  • Open a ssh session to volumio.local and run the Pi-hole install script.
  • Open /etc/lighttpd/lighttpd.conf and set these values:
    server.port = 8080
    server.errorlog = "/tmp/lighttpd_error.log"
    accesslog.filename = "/tmp/lighttpd_access.log"
  • Reload the lighttpd settings with sudo service lighttpd reload or reboot the Raspberry Pi.
  • Go to the Pi-hole web interface at http://volumio.local:8080/admin/
  • (Optional) Set a default web page at the web root:
    cd /var/www/html/
    cp index.lighttpd.orig index.html

    Or set your own index page.

And while you are at it, stop the dhcp-daemon and delete the secondary IP address.

Link

https://www.cyberciti.biz/tips/installing-and-configuring-lighttpd-webserver-howto.html

Apache2 proxy setup.

Om lan servers via internet te benaderen en daarbij niet te veel poorten te hoeven openen kun je Apache2 gebruiken als proxy server.

Voorbeeld salamanders:

Opslaan als salamanders.wasietsmet.nl.conf in /etc/apache2/sites-available.

<VirtualHost *:80>

    Servername salamanders.wasietsmet.nl

    ProxyRequests Off

    ProxyPreserveHost On

    <Location />
        ProxyPass "http://192.168.0.199/"
        ProxyPassReverse "http://192.168.0.199/"
    </Location>

    SetEnvIf Request_URI "^/api/getdevice" dontlog

    CustomLog "|/usr/bin/rotatelogs /var/www/salamanders.wasietsmet.nl/log/access%d-%m-%Y 86400" vhost_combined env=!dontlog
    ErrorLog "|/usr/bin/rotatelogs /var/www/salamanders.wasietsmet.nl/log/error%d-%m-%Y 86400"

</VirtualHost>

Nu alleen nog Apache2 op de hoogte stellen:

a2ensite salamanders*
service apache2 reload

En het werkt.

De links:

https://www.leaseweb.com/labs/2014/12/tutorial-apache-2-4-transparent-reverse-proxy/
https://www.howtoforge.com/setenvif_apache2
https://www.jamescoyle.net/how-to/116-simple-apache-reverse-proxy-example