[OH3] Reverse proxy to subdirectory

  • Platform information:
    • Hardware: aarch64/4GB/64GB
    • OS: Manjaro
    • Java Runtime Environment: java 11
    • openHAB version: 3.0
  • Issue of the topic: Run openhab in a subdirectory in nginx reverse proxy
  • Please post configurations (if applicable):
    • Items configuration related to the issue: none
    • Sitemap configuration related to the issue: none
    • Rules code related to the issue: none
    • Services configuration related to the issue: none
  • If logs where generated please post these here using code fences: none

Hi,
Did someone manage to run openhab 3.0 in a subfolder in nginx reverse proxy mode?
I’d like to run in http://myserver/smarthome, ideally it should be as easy as configuring nginx as:

 location /smarthome {
         return 301 $scheme://$host/smarthome/;
 }

location /smarthome/ {
        proxy_pass                          http://localhost:8080/;
        proxy_buffering                     off;
        proxy_set_header Host               $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;
}

However this is not working. If I navigate to http://myserver/smarthome i can only see a blank page. Network pane shows the following:

I remember having a slightly different configuration for BasicUI in OH2, which works a little better, but still unusable:

location /smarthome {
        return 301 $scheme://$host/smarthome/;
}

location /smarthome/ {
        proxy_pass                          http://localhost:8080/;
        proxy_buffering                     off;
        proxy_set_header Host               $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";

        sub_filter_types    application/javascript text/xml text/css text/javascript application/json text/plain;
        sub_filter_once     off;

        sub_filter          '/rest/'       '/smarthome/rest/';
        sub_filter          '"/icon/'       '"/smarthome/icon/';
        sub_filter          '"/basicui/'    '"/smarthome/basicui/';
}

The result is this, all requests complete with HTTP status 200, but it doesn’t work yet:

Any idea on how to fix this?

Compared to your OH2 configuration this one ( Nginx as reverse proxy for OH2 at non-root location - #8 by evertramos ) has a slightly different "proxy_set_header Host " entry. In post 12 in that thread configuration for paperui is mentioned.
I did not test but hopes it helps in your case.

I don’t see any configuration where paper ui was confirmed working…
Also, that thread has only 11 posts… what do you mean by post 12?
The difference in host header is a test I made. Using $host/smarhome is even worse than $host

After messing around and wasting many hours I ended up thinking this is not possible in OH3.
I will use a subdomain even if this is not what I wanted to do.

Read this post, for basicUI and the REST API in OH3.
It works fine for me. I don’t need the mainUI at this point though, so you might have to do some additional tweaking.