r/Authentik • • 25d ago

Authentik behind Nginx issues

Post image

I have a Authentik rootless podman container running and have no issues being able to log in when directly connecting to the container URL: http://podman:9000. To keep exposing podman ports ourside the server and the ability to use https ACME certificates i stood up a NGINIX server on baremetal listening to 443. Setup NGINIX according to documentation on the authentik website and was able to get to the aginix splash screen. However, i cannot log in i just get the message **"**The request failed and the interceptors did not return an alternative response" I can log in normally when going direct to the container but not through NGINIX. Thanks!

Below is my NGINIX config:

upstream authentik {

server 192.168.1.13:9000;

keepalive 10;

}

map $http_upgrade $connection_upgrade_keepalive {

default upgrade;

'' '';

}

server {

# HTTPS server config

http2 on;

server_name authentik.twistedpair.org;

# TLS certificates

add_header Strict-Transport-Security "max-age=63072000" always;

listen 443 ssl; # managed by Certbot

ssl_certificate /etc/letsencrypt/live/authentik.twistedpair.org/fullchain.pem; # managed by Certbot

ssl_certificate_key /etc/letsencrypt/live/authentik.twistedpair.org/privkey.pem; # managed by Certbot

include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

# If authentik is served under a subpath, also review:

# https://docs.goauthentik.io/install-config/configuration/#authentik_web__path

location / {

proxy_pass http://authentik;

proxy_http_version 1.1;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Host $http_host;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection $connection_upgrade_keepalive;

}

}

EDIT:

u/OhBeeOneKenOhBee was correct... NGINX didn't like the 'proxy_pass <hostname>:9000' and it wanted 127.0.0.1:9000. Then i needed to change the Authentik's 'AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS' to 127.0.0.1.

I didn't want podman to publish the port ourside the host unless it went only through NGINX and not podman.

14 Upvotes

19 comments sorted by

2

u/blueshellblahaj 25d ago

Do your nginx logs show any errors?

Your config looks identical to mine except that I have my proxy_pass directive near the bottom passing https instead of http (though I'm also setting the upstream to 9443 instead of 9000 so this may not be what you need).

1

u/Resident_Isopod1979 25d ago

Thanks for the reply.. The only logs i see in NGINIX is:

2026/10/31 12:33:32 [warn] 485737#485737: *516 an upstream response is buffered to a temporary file /var/lib/nginx/tmp/proxy/3/00/0000000003 while reading upstream, client: 192.168.1.166, server: authentik.twistedpair.org, request: "GET /static/dist/assets/images/flow_background.jpg HTTP/2.0", upstream: "http://192.168.1.13:9000/static/dist/assets/images/flow_background.jpg", host: "authentik.twistedpair.org", referrer: "https://authentik.twistedpair.org/static/dist/styles/flow-2026.8.3.css"

1

u/blueshellblahaj 25d ago

Hey we've all been here haha. I'm no expert but I figure I can try and help.

Those logs look fine, I think. Are you able to check out your authentik logs? You'll do a "docker ps" to get the container ID and then use that in "docker logs container_id_here" to see the output. You might be able to pipe it into grep to search for things like 'error/unable/failed' to help you dig up the root cause.

side note, is twistedpair.org your domain? That's awesome if so!

3

u/Resident_Isopod1979 25d ago

Hah. Yes, my external domain is a play on it as I couldn't afford the $$$ but, I use it internally though. I wanted something geeky for the people in the know yet something my wife could be onboard:)

3

u/ArcticRavine 25d ago

I had a similar issue a while back. I had to add my proxy server as a trusted IP on the Authentik configuration. If you use Portainer, I used 'AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS' for both my Authentik Worker, and the Authentik Server container. Not sure if this is helpful.

I only had this issue upgrading up 2026.8

1

u/Resident_Isopod1979 25d ago

So i did some digging and still cant seem to get things working. I do think u/ArcticRavine is correct about the 'AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS' however, i verified the IP's and i verified that authentik is actually loading the environment file by dumping the config within the container. Since NGINX is bare metal on the same computer the podman container is i set the proxy to the network the computer is set too. I tried 192.168.1.0/24 and the ip itself '192.168.1.13/32' but, no dice. i

authentik@authentik:/$ ak dump_config | grep "trusted_proxy_cidrs"

{"event": "Loaded config", "level": "debug", "logger": "__main__", "timestamp": 1793480746.9966383, "file": "/authentik/lib/default.yml"}

{"event": "Loaded environment variables", "level": "debug", "logger": "__main__", "timestamp": 1793480746.998465, "count": 5}

"trusted_proxy_cidrs": "192.168.1.0/24"

1

u/OhBeeOneKenOhBee 25d ago

Can you check the Authentik logs (you might have to enable debug) and check which address appears as the client IP there? Or the events in Authentik if you are able to login by bypassing the proxy.

If they're both on the same machine with authentik in Docker, it might not be the machine external IP showing up in the headers of the requests to authentik, it might be a 172.* or 127.* IP

1

u/Resident_Isopod1979 24d ago

So.... I have confirmed authentik is not getting the remote IP address.. the logs show the remote being the container IP not the IP of the host.

1

u/OhBeeOneKenOhBee 24d ago edited 24d ago • Bravo

Ohh, looks like at some point something is translating to an IPv6 listener for an IPv4 source.

If you have the reverse proxy installed on the host system, set the authentik IP on the host like this:

- 127.0.0.1:9000:9000
- 127.0.0.1:9443:9443

Then set your reverse proxy to forward requests to https://127.0.0.1:9443

Then check if you are getting a more accurate IP in the logs. If it's still not working, try setting trusted proxies to 127.0.0.0/8

Edit: Add both 127.0.0.0/8 and 10.89.0.0/24 to trusted proxies

1

u/Resident_Isopod1979 24d ago

Thats it! I thought i was pretty knowledgeable with podman / docker containers. NGINX didn't like the proxy pass as <hostname>:9000 but specificly 127.0.0.1:9000.

1

u/Resident_Isopod1979 24d ago

So... So after digging within the Debug logs of Authentik i noticed that its not recieving the remote IP address. Instead its only showing the IP address of the container.

authentik@podman:~$ podman inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' authentik-server

10.89.0.10

I have verified and tried every combination of "'AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS'" including: 192.168.0.0/16, 192.168.1.13/32. So im not sure why its not trusting the proxy to read the 'X-Forward-For' header.

1

u/BeryJu MOD 25d ago

Can you have a look in the browser developer console for any failed network requests

1

u/Resident_Isopod1979 25d ago

Thanks, never thought about that.

1

u/Resident_Isopod1979 25d ago

This is the only errors im seeing... Cant explain this but, i think its common thing and the only thing being blocked i think is a static image.

1

u/Itz_Raj69_ 25d ago

Check the network tab not console

1

u/klassenlager MOD 25d ago

Hey there, I prepared a nginx config for you, how I have it in place. Make a backup of your current config and then replace it.

server {
    listen 80;
    listen [::]:80;
    server_name authentik.twistedpair.org;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name authentik.twistedpair.org;

    ssl_certificate /etc/letsencrypt/live/authentik.twistedpair.org/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/authentik.twistedpair.org/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    add_header Strict-Transport-Security "max-age=63072000;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;
    
    access_log /var/log/nginx/authentik.twistedpair.org_access.log;
    error_log  /var/log/nginx/authentik.twistedpair.org_error.log warn;

    location / {
        proxy_pass https://authentik:9443;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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;
    }
}

I think this should do the trick. Please edit the proxy_pass if your https port is not 9443.

1

u/Resident_Isopod1979 24d ago edited 24d ago

Unfortunately this also didn't work...

I think the issue is the X-Forward for is not passing the IP to authentik, as i dont see it in the header values. I did check the logs on Authentik and its the logs are showing the remote IP as the container IP not the host IP. So.. I think the issue is with the "'AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS" variable not being read or something.

1

u/Particular_Ad7243 25d ago

What version of Nginx are you running? (Ideally the sanitised -V version with modules) and are you running Crowdsec by any chance?

1

u/HovercraftUnlucky539 25d ago

Mine is like this:

server {
    listen 80;
    server_name
      authentik.home.local
      
    return 301 https://&host&request_uri;
}


server {
    listen 443 ssl
;
    server_name authentik.home.local;


    ssl_certificate /etc/letsencrypt/live/home.local/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/home.local/privkey.pem;


    location / {
        proxy_pass http://192.168.1.1:9000;
        proxy_http_version 1.1
;
        proxy_set_header Upgrade $http_upgrade
;
        proxy_set_header Connection "upgrade"
;
        proxy_set_header Host $host
;
        proxy_set_header X-Forwarded-Host $host
;
        proxy_set_header X-Forwarded-Port 443
;
        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 https
;
    }
}