How to redirect (sub)domain to ip and port

I have installed OpenWrt on an x86 machine, got the initial setup working and I can access the router at openwrt.lan. I have a couple other services installed on this machine, which have their own frontend, e.g. I can access Portainer via openwrt.lan:9000, Home Assistant via openwrt.lan:8123 or Frigate via openwrt.lan:5000. Alternatively, I can replace openwrt.lan with the IP address of my router which is 192.168.3.1 in my case.

I don't want to remember all the ports all the time, so I would like to just enter e.g. portainer.openwrt.lan and get redirected to port 9000 automatically. How do I set that up?

Also, I have secured the frontends of those services with SSL and can only access them via https://openwrt.lan:9000 and entering http://openwrt.lan:9000 will return a 400 error. How do I redirect the HTTP requests to HTTPS?

DNS is unaware of ports.

You could however do redirects in the web server
if you set up aliases like alias.site.com or site.com/alias

Ok, I think that's ringing a bell on the stuff I learned in uni some time ago....

So I could set up an nginx server with the required proxy_pass entries to the other ports like this?

server {
    listen 80;
    server_name portainer.openwrt.lan;
    location / {
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:9000;
        proxy_redirect off;
    }
}

...

I would of course have to change /etc/config/uhttpd as well since LuCI is currently listening to port 80 and 443. Would that be a viable solution?

Yeah, would work, if it can't be done in uhttpd.

But it seems to support it, look at https://openwrt.org/docs/guide-user/services/webserver/uhttpd

Nginx can probably replace uhttpd too, but you'd have to look for info regarding how to configure it.

That's even easier. Just took a couple mins to change the file, thanks for the link

uhttp (cgi redirector) can handle host portion nicely see;

one way to handle (wildcard) dns...;

dhcp.@dnsmasq[0].address='/router/10.2.3.1'

kind of a long way around doing (non-local-pages) things tho' unless your websites come and go frequently...

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.