Openhab 4.x and log viewer behind nginx proxy

I saw some post in the openHAB 4.3 Release Discussion concerning problems, that the log viewer in the GUI is not working.

The problem described there is that no logs are shown and the buttons start, pause and stop are dysfunktional.

In my case this is due to the fact that my openhab installation is sitting behind an nginx proxy. By browsing the forum discussions I got the impression, that the GUI is using websockets to get the stream of logs.

So in case the problem is related to openhab sitting behind an nginx proxy, you have to alter the nginx configuration to support websockets.

This is mainly done through the directives:

server {
  ...

  location / {
    ...
    proxy_set_header Upgrade              $http_upgrade;
    proxy_set_header Connection           "Upgrade";
  }

  proxy_http_version 1.1;

So in my case the configuration looks like:

server {
    server_name smarthome.c.internal;

    listen 443 ssl; # managed by Certbot

    ssl_certificate /etc/letsencrypt/live/smarthome.c.internal/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/smarthome.c.internal/privkey.pem; # managed by Certbot

    # Cross-Origin Resource Sharing
    add_header 'Access-Control-Allow-Origin' '*' always;
    add_header 'Access-Control-Allow_Credentials' 'true' always;
    add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always;
    add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;

    location / {
        proxy_pass                            http://localhost:8080/;
        proxy_set_header Host                 $http_host;
        proxy_set_header X-Real-IP            $remote_addr;
        proxy_set_header X-Forwarded-For      $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto    $scheme;
        proxy_set_header Upgrade              $http_upgrade;
        proxy_set_header Connection           "Upgrade";
    }

    proxy_http_version 1.1;

    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = smarthome.c.internal) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    server_name smarthome.c.internal;

    listen 80;

    return 404; # managed by Certbot
}

After that the log viewer in the GUI came alive.

Cheers

3 Likes

This is excelent information to add to the https://www.openhab.org/docs/installation/reverse-proxy.html docs.

1 Like

Yeah, also thought so and already submitted a pull request for this.

1 Like

Already there, but not in the stable docs:

This is the same?!

1 Like

Yes, @franks was way ahead of me. I was looking at the stable docs, not latest.

But anyway his PR adds important stuff that mine did not totally cover.