Nginx reverse proxy to docker image

The issue I am facing:
I'm having issues with a nginx reverse proxy to the docker image pihole/pihole:latest.
I have a home "control panel" where I have several systems in in reverse proxies and a bunch of stuff where the pi-hole admin GUI is one.
When I log in to the pi-hole admin panel I get logged out of my session in nginx.
After I log in to the control panel again, I'm logged in to both pi-hole and control panel.

Details about my system:
nginx version: nginx/1.18.0 (Ubuntu)
nginx module: auth_request
docker image pihole/pihole:latest

The control panel lives in the location /home/ and the pi-hole reverse proxy lives in /home/pihole/
nginx conf:

location ^~ /home/ {
auth_request /auth;
location ~ ^(?!\/home\/pihole\/).*\.php$ {
      include fastcgi.conf;
      fastcgi_pass unix:/run/php/php7.4-fpm.sock;
      fastcgi_buffers 16 16k;
      fastcgi_buffer_size 32k;
    }
location  /home/pihole/ {
add_header Content-Security-Policy "default-src 'self'; font-src *;img-src * data:; script-src 'self' 'unsafe-inline' *; style-src 'self' 'unsafe-inline' *; frame-ancestors *";
      proxy_redirect /admin/ /home/pihole/;
      proxy_pass http://127.0.0.1:8008/admin/;
      proxy_set_header X-Frame-Options "SAMEORIGIN";
    }
---other conf omitted---
}

What I have changed since installing Pi-hole:
The docker image is standard :latest and port 53 and 8080 are routed to the docker image.

After a bunch of debbuing I found out that the culprit was this:
location ~ .php$ {
In side the / location.
After a change to:
location ~ ^(?!/home/pihole/).*.php$ {
It no longer processes the request that supposed to go into the proxy_pass.

Working conf:

server {
  listen 443 ssl http2;
  server_name         <server name omitted>

  root        /var/www/;
  index       index.html index.php;

  location /home/ {
    location /home/pihole/ {
      proxy_redirect /admin/ /home/pihole/;
      proxy_pass http://127.0.0.1:8008/admin/;
    }
---not applicable conf omitted--
    location ~ ^(?!\/home\/pihole\/).*\.php$ {
      include fastcgi.conf;
      fastcgi_pass unix:/run/php/php7.4-fpm.sock;
      fastcgi_buffers 16 16k;
      fastcgi_buffer_size 32k;
    }
  }
  location ~ ^(?!/home/).*\.php$ {
    include fastcgi.conf;
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    fastcgi_buffers 16 16k;
    fastcgi_buffer_size 32k;
  }
}

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