Hello everyone!
A very new users of pi-hole and the very first post here.
I have pihole v6, running on port 8008 and it's working fine using http://my-ip:8008/admin without any issue and now trying to running it behind Nginx (installed on the same machine) reverse proxy to have centralized access for few other services. This is my Nginx host configuration for pihole:
If I try http://cnrpi5.example.net/pihole/ on the browser, it simply redirects to cnrpi5.example.net/admin/http://cnrpi5.example.net/pihole/ i.e. without the port number, resulting a 404 Not found.
Is there anything else I need to do in pi-hole configuration to make it work, as the very simialr Nginx configuration is working for other apps or I have missed something in reserve proxy that specifically required for pi-hole? Any pointer/help would be really appreciated!
I am a bit confused by your config - do you want to offer Pi-hole on cnrpi5.example.net/pihole as your config suggests, or do you want to redirect to http://cnrpi5.example.net:8008/admin as your text says?
I would offer Pi-hole through your nginx, so there just needs one port to be open.
So bind Pi-hole to 127.0.0.1:8008, do two reverse-proxy location entries for /pihole/admin and pihole/api and maybe a redirect from pihole to pihole/admin and you are done.
See my example config that Bucking_Horn already linked.
good catch, that's a typo; sorry about that.
As you said, the endpoint shoud be: http://cnrpi5.example.net/pihole/not/admin. I copied the URL after it redirected hance, the typo.
I'll have a look at config that you referenced and report back. ty!
Okay, I have made some progress, following the config from stefan
With this config:
upstream local {
server 127.0.0.1:8008;
}
server {
listen 80;
server_name cnrpi5.example.net;
## Server Logs
access_log /var/log/nginx/pihole_access.log;
error_log /var/log/nginx/pihole_error.log error;
location /admin/ {
proxy_pass http://local/admin/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
now if I do http://cnrpi5.example.net/admin it perfectly forwarding to http://cnrpi5.example.net/admin/login and working just fine.
But I want to type http://cnrpi5.example.net/pihole/ in the browser (as UniFi Controller also running on the same machine and I like to have http://cnrpi5.example.net/unifi for that) and then redirect wherever it needs to be to get the GUI . Simply changing the location to location /pihole/ {...} not working. What ectra bit do I need to make it work?
BTW, what is that /api for - required for pi-hole to work?
Not even a login works without that endpoint. You really shouldn't skip this in your config.
That's a bit more difficult as internal redirects seem to use absolute and not relative paths. Just simply changing the config will result in a redirect loop:
yes, it is working and still working. Why you think it didn't it?
With a configuration exactly like the above, it's working absolutely fine using endpoint http://cnrpi5.example.net/admin but I wanted to use http://cnrpi5.example.net/pihole instead.
re. about using http://cnrpi5.example.net/pihole - I think have spent/wasted enough time on that and simply moved to https://pihole.example.net/ instead and I'm okay with that atm. This is the config I'm currently using, if anyone interested:
also, I strongly think, Pi-hole should really redirect to /admin automatically. it's really troublesome behind a multi-homed Nginx. If it's already not asked for, how do I do a feature request?
Thanks, good to know! I'd suggest including this warning in the setting description until it is fixed.
I know you only get it in "All settings", but even as an expert user, I somehow expect them to work
In the config above, you are missing the /api endpoint. If it's working, you most probably had it in your config, but didn't paste that part. That makes discussing more difficult
We noticed this was broken only after v6 release (We would have disabled the option if we had noticed it earlier).
To add this to the settings page, we will need to release a new Pi-hole version anyway. I think it will be better if we just fix the issue and release a fixed version. Just be a patient for a little longer.
I see, the login page still comes up without /api/ but probably I was so over the moon to see the login page again, I didn't even bother trying to login before putting /api in