'how to return json data instead nginx 401 page on auth request

let me asking

this is my nginx config:

location /index {
    auth_request        /auth;
    proxy_pass          http://127.0.0.1:8081;
    auth_request_set $user $upstream_http_x_forwarded_user;
    proxy_set_header X-Forwarded-User $user;
}

location /auth {
    proxy_pass                      http://127.0.0.1:8081;
    proxy_set_header                Host $host;
    proxy_set_header                Content-Length "";
    proxy_pass_request_body         off;
    proxy_set_header X-Original-URI $request_uri;
}

and in the enpoint of auth just return 401 status and the message:

app.Get("/auth", func(c *fiber.Ctx) error {
    return c.SendStatus(fiber.StatusUnauthorized)
})

but why nginx not printed the message but just show 401 page of nginx so how to print from my response

thanks in advance



Solution 1:[1]

solved with

error_page 401 =401 /auth;

in /index path

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Umar