[Solved] How do I redirect to a /path with Nginx Proxy Manager?
from Sunny@slrpnk.net to selfhosted@lemmy.world on 29 Sep 10:37
https://slrpnk.net/post/13785411

Hi folks,

Just set up Nginx Proxy Manager + Pihole and a new domain with Porkbun. All is working and I have all my services service.mydomain.com, however some services such as pihole seem to be strictly reachable with /admin at the end. This means with my current setup it only directs me to pihole.mydomain.com which leads to a 403 Forbidden.

This is what I have tried, but with no prevail. Not really getting the hang of this so would really appriciate a pinpoint on this :)

#selfhosted

threaded - newest

sk@hub.utsukta.org on 29 Sep 10:41 next collapse

Add the following in Advanced tab

location / {
   return 301 /admin;
}

location /admin {
   proxy_pass [url=http://<Pi-hole-IP>:<Pi-hole-Port>/admin;]http://<Pi-hole-IP>:<Pi-hole-Port>/admin;[/url]
   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;
}

replace the IP and port
Sunny@slrpnk.net on 29 Sep 11:01 collapse

Thank you for providing this, however when i now browse to pihole.mydomain.com it gives me a 404, and the URL is directed to pihole.mydomain.com/admin:8118. E.g. the port is somehow ending up at the end of the url haha.

sk@hub.utsukta.org on 29 Sep 11:03 collapse

@Sunny' 🌻 that must not happen, did you remove the custom location from before? The above is working with my pihole setup

Sunny@slrpnk.net on 29 Sep 11:08 collapse

Ahhh i got it working now! Thanks a bunch for the help, been trying to get this to work for hours now hehe

K3can@lemmy.radio on 01 Oct 16:52 next collapse

If you’re going to be playing with custom locations and such, it might be worth using nginx directly instead of through the limitations of NPM.

TedZanzibar@feddit.uk on 02 Oct 11:09 collapse

Just tried this myself and mine does the same thing but I don’t have anything set in the custom locations tab. What did you do to resolve it?

Sunny@slrpnk.net on 02 Oct 12:00 collapse

Remove any custom locations (if u have tried to add any), and then simply copy paste this into the advanced tab. Dont forget to change the <IP+PORT>

location / {
    return 301 /admin;
}
location /admin {
    proxy_pass http://<YOUR IP:PORT>/admin;
    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;
}

Let me know how it goes :)

TedZanzibar@feddit.uk on 02 Oct 13:57 collapse

Yeah that’s exactly what I’d done but it was insisting on trying to redirect me to the site on port 4443 for some reason.

Fixed it in the end by reverting the NPM config to default (no advanced settings) and instead using Pihole’s VIRTUAL_HOST=pihole.mydomain.internal environment variable in the Docker compose file.

Cheers for your help anyway!

[deleted] on 30 Sep 03:34 next collapse

.

Bakkoda@sh.itjust.works on 30 Sep 12:06 collapse

Side question: Are you exposing your pihole externally?

Sunny@slrpnk.net on 01 Oct 06:27 collapse

nope. Been using Tailscale to acesss my stuff from home.