Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95419

Nginx redirect only for specific URI

$
0
0

@ninjadog wrote:

So, I have running a Digital Ocean (DO) droplet running with Algo VPN and nginx. The droplet has a domain associated with it (xyz.com). Nginx setup uses letsencrypt certificate. Connections to xyz.com:80 are redirected to a VPN client (10.19.49.2) on which HA is running. I can successfully connect to lovelace by means of using xyz.com in the browser. But what I want to do is not consume the / namespace on the URI. In other words I’d like to use xyz.com/my_ha for example. But I cannot get it to work - I have to say I am new to reverse proxy so learning but just stuck now.

This is my setup

configuration.yaml

http:
  base_url: https://xyz.com
  use_x_forwarded_for: true
  trusted_proxies: 10.19.49.1 #-- my DO droplet's VPN IP

/etc/nginx/sites-enabled/default

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    server_name xyz.com;
    listen [::]:80 default_server ipv6only=off;
    return 301 https://$host$request_uri;
}

server {
    server_name xyz.com;
    ssl_certificate /etc/letsencrypt/live/xyz.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/xyz.com/privkey.pem;

    listen [::]:443 ssl default_server ipv6only=off;
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
    ssl on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;

    proxy_buffering off;

#
#-- here I tried changing location '/' to '/my_ha' but I get the 404: error if not set to just /
#
    location / {
        proxy_pass http://10.19.49.2:8123;  #-- My VPN client running HA
        proxy_set_header Host $host;
        proxy_redirect http:// https://;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}

As per comment above, I tried changing location / to /my_ha but when I do that I get the 404: error; set it back to / and all works again, i.e. I can use https://xyz.com and my ha instance on a VPN client is presented (lovelace). Great. But not quite what I want (which is https://xyz.com/my_ha

Is what I seek even possible, and how please - explanation would help tremendously; I’ve tried, but got as far as my tech head allows me.

TIA

(p.s. Sorry about the colour scheme of code above, it’s not me, it’s whatever HA forums is doing to it.)

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95419

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>