Use NGINX to redirect to one UI only?

Hi I’m following this tutorial on OH2 official web page : http://docs.openhab.org/installation/security.html#nginx-reverse-proxy

My question is I just want my domain to redirect to localhost:8080/habpanel/index.html#/ only. Because the other UIs don’t appeal much to me.

How can I edit the nginx conf file to do that? I try to replace “http://localhost:8080” by “http://localhost:8080 localhost:8080/habpanel/index.html#/” but the result always say : “Connection lost” on my web browser

Please HELPPP!

I’m trying to do the same. Just want to check if someone has solved it.

I think you’d be better redirecting another address eg: http://localhost:8088 to habpanel and keep the option to access 8080 for paperui and rest api

Its about accessing default habpanel from internet. Access other UIs can be achieved from local network so no need to create multiple locations.

I would like to know it too, localhost:8080/habpanel/index.html# to a simple http://rpi3 would be awesome

Has anyone been able to figure this out? I have mine set up as habpanel.mydomain.local but get the dreaded “connection lost” and I think it’s because it’s trying to access files outside of the /habpanel directory (like /rest) but can’t reach them because the folder doesn’t exist under /habpanel, it’s above it in the directory structure. If there was a way to have all 404 errors redirect to servername.mydomain.local:8080/path in NGINX I think it would work but i’ve had no luck figuring out how to do that.

I have also set up openhab.mydomain.local to redirect to servername.mydomain.local:8080 and all dashboards work fine this way but having to select which one every time is kind of annoying if i’m not using a bookmark.

Can you post a copy of etc/nginx/sites-enabled/yourfile?

Do you have multip!e? I believe you need a minimum of two. The default one and your custom one.

This would be required for any assistance.

Sorry, I have both a default one and a Habpanel one. Both habpanel.mydomain.local and openhab.mydomain.local resolve just fine from both the openhab box and the client. It’s honestly probably wrong but i’ve had such a hard time trying to find a good tutorial on this scenario with NGINX so any input is greatly appreciated:

Habpanel (loads but gets “connection lost” because it can’t reach habpanel.mydomain.local/rest)

server {
       listen 80;
       listen [::]:80;

       server_name habpanel.mydomain.local;

       root /var/www/html;

       index index.html index.htm index.nginx-debian.html;
       location / {
                proxy_pass http://openhab.mydomain.local:8080/habpanel/;
                proxy_buffering                       off;
                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;
       }
}

Default (this works fine with all UIs)

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                proxy_pass http://openhab.mydomain.local:8080/;
        }
# the rest of the default file comments
}

I was able to hack it to work with the following config, but there must be a better way than to keep adding location blocks every time there’s a bad URL

# Virtual Host configuration for example.com
# 
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
server {
       listen 80;
       listen [::]:80;

       server_name habpanel.mydomain.local;

       root /var/www/html;

       index index.html index.htm;
       location /rest/ {
                proxy_pass http://openhab.mydomain.local:8080/rest/;
       }
       location /static/ {
                proxy_pass http://openhab.mydomain.local:8080/static/;
       }

       location / {
                proxy_pass http://openhab.mydomain.local:8080/habpanel/;
                proxy_buffering                       off;
                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;
       }
}

1 Like

I believe the problem lies with calling the habpanel site /

I need to look at this on my end, I have a couple thoughts. Not sure I can achieve what i am thinking though.

Hello everybody,
Do you find a solution ? I have the same problem. I need to load only one panel : habpanel. I need to block all except habpanel… because i don’t want someone delete something in paperui or other…

Thanks

I got it working :slight_smile:

This is my nginx-config-File:

 server {
        listen 80;
        listen [::]:80;

        server_name home.nst;

        return 301 https://$server_name$request_uri;
}

server {
        listen 443 ssl;
        listen [::]:443 ssl;
        server_name home.nst;

        ssl_certificate         /etc/ssl/local/home.nst/home_nst_190203.bundle.crt;
        ssl_certificate_key     /etc/ssl/local/home.nst/home_nst_190203.key;

        location /rest/ {
                proxy_pass http://127.0.0.1:8080/rest/;
        }
        location /static/ {
                proxy_pass http://127.0.0.1:8080/static/;
        }

        location = / {
                return 301 /index.html#;
        }

        location / {
                proxy_buffering                       off;
                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_pass http://127.0.0.1:8080/habpanel/;
        }
}

Just add the “location = /”-part and it should work.

1 Like

None of the above solutions worked for me using Openhab 3.4.
What finally worked after a lot of experiments is:

server {
	listen 80;

	server_name your.server.name;

	location /rest/ {
		proxy_pass http://localhost:8080/rest/;
	}
	location /static/ {
		proxy_pass http://localhost:8080/static/;
	}

	location / {
		proxy_pass                            http://localhost:8080/habpanel/;
		proxy_buffering                       off;
		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_read_timeout                    3600;
	}

}