nosduco / nforwardauth

Simple and minimalist forward auth service intended for use with reverse proxies (Traefik, Caddy, nginx, etc)
MIT License
117 stars 3 forks source link

How to you nforwardauth with nginx-proxy-manager #54

Open vvstubbs opened 3 months ago

vvstubbs commented 3 months ago

I would like to use nforwardauth in place of the basic-auth that NPM currently uses, an proper login screen is much more professional, is there any exables on how to use nforwardauth with NPM, as it's based on nginx I would think it's possble

jayverity commented 1 week ago

Decided to try it out for you. I spun up a new NPM instance and proxied Dozzle behind it, and with a little experimenting, got this to work. Put this in the advanced section for the host you are proxying, making changes according to the comments. Do not put anything in the custom locations tab, this handles the / location at the bottom. You should only have to edit the three lines I've commented on for this to work.

    location /nforwardauth {
        internal;
        proxy_pass_request_body off;
        proxy_set_header Host "auth.example.com"; # Change this to whatever server name you use publicly for nforwardauth
        proxy_pass http://nforwardauth:3000/nginx; # How NPM reaches the auth server on the docker network.  Leave the /nginx there.  If your container_name is nforwardauth and you left the default port, you don't need to edit this line at all.
    }

    error_page 401 = @auth_redirect;
    location @auth_redirect {
        # Edit the next line with the public urls of the auth server and the app you are protecting
        return 302 https://auth.example.com/login?r=https://app.example.com; 
    }

    location / {
        auth_request /nforwardauth;
        auth_request_set $auth_status $upstream_status;
        proxy_pass $forward_scheme://$server:$port;
    }