Configuration Webserver Apache/Nginx

Hello Christian,

for those reasons I’m using Apache as well :wink:

I’m gonna paste my working Apache config down below. But first I would like to tell you how I got there. First I was using OpenEMS UI with plain HTTP (unencrypted), just like your Apache config snippet implies. In that use case I did not use Apache as Proxy for the websocket connection of the UI at all, but directly entered the corresponding WS URL into the UI environment file.

Later I wanted to use HTTPS to connect my browser to my UI. I’m planning to switch my backend from Metadata_Dummy to Metadata_File while I’m working on a MR to add some simple user-auth to Metadata_File. That’s because while being a big Odoo fanboy, I see that there is going to be smaller deployments which don’t account for a full Odoo instance just for backend Edge/User auth.

So for HTTPS I had to find a solution to have websocket use HTTPS as well (AFAIK browsers would not accept otherwise). So I was trying to setup Apache to act as HTTPS endpoint for the websocket connection and proxy this to the websocket endpoint. I did have a bit of a struggle, most of all because of some general misconceptions of mine about websocket in general. Finally I made it with close to zero configuration effort, as with apache there is a module mod_proxy_wstunnel. When enabling this module, proxy for websocket will work magically without much further work. The one thing that kept me struggling for hours was that testing this wstunnel won’t work by entering the websocket URL into your browser address bar, as your browser then would not issue a websocket request, which then results in a very misleading error message in your Apache error log. Finally when I realized that, I just gave OpenEMS UI a go and it worked.

So finally here is my working apache config, and remember you need module proxy_wstunnel enabled along with those other proxy modules needed. And remember, you will want the “ErrorDocument …” Line in your config :wink:

 <VirtualHost _default_:443>
                ServerAdmin webmaster@localhost

                DocumentRoot /opt/openems-ui
                ErrorDocument 404 /index.html

                ProxyPass /openems-backend-ui ws://localhost:8082/
                ProxyPassReverse /openems-backend-ui ws://localhost:8082/

                # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
                # error, crit, alert, emerg.
                # It is also possible to configure the loglevel for particular
                # modules, e.g.
                #LogLevel info ssl:warn

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

                ... all the SSL stuff ...

                <Directory /opt/openems-ui>
                        Options Indexes FollowSymLinks
                        AllowOverride None
                        Require all granted
                </Directory>

        </VirtualHost>
3 Likes