LumberManCZ
ZZerops
•Created by LumberManCZ on 12/9/2024 in #💪・community-support
NGINX Authentication Based on Subrequest Result
Hi, I am solving a problem with authentication based on the result of a sub-request in nginx.
´´´
server {
listen 80 default_server;
listen [::]:80 default_server;
Servername ;
root {{{.DocumentRoot}};
location / {
root {{{.DocumentRoot}}/web;
index index.html index.php;
#use this for a nice url
try_files $uri /$uri /index.html /index.php$is_args$args;
}
location /dist {
auth_request /auth;
#Error
error_page 401 = @auth_401_error;
error_page 403 = @auth_403_error;
error_page 404 = @auth_404_error;
error_page 500 = @auth_500_error;
error_page 502 = @auth_502_error;
try_files $uri $uri/ /index.php?$query_string; } location = /auth { internal; proxy_pass https://example.com/api/auth; proxy_method POST; proxy_set_header Accept "application/json"; proxy_set_header X-Original-URI $request_uri; proxy_set_header Content-Length ""; proxyredirect off; } ´´´ The call keeps returning me intrarnal error 500 instead of 401 nginx: 2024/12/09 09:14:10 [error] 686#686: *23 auth request unexpected status: 301 while sending to client, client: 10.3.132.4, server: , request: "GET /dist HTTP/1.1", host: "phpnginx0.xxx.zerops.app"
try_files $uri $uri/ /index.php?$query_string; } location = /auth { internal; proxy_pass https://example.com/api/auth; proxy_method POST; proxy_set_header Accept "application/json"; proxy_set_header X-Original-URI $request_uri; proxy_set_header Content-Length ""; proxyredirect off; } ´´´ The call keeps returning me intrarnal error 500 instead of 401 nginx: 2024/12/09 09:14:10 [error] 686#686: *23 auth request unexpected status: 301 while sending to client, client: 10.3.132.4, server: , request: "GET /dist HTTP/1.1", host: "phpnginx0.xxx.zerops.app"
9 replies