I use nginx as the only entry point to my solution.
My goal is to send some authentication url before proceeding.
I found a module named: ngx_http_auth_request_modulethat is suitable for solving my problem.
http://nginx.org/en/docs/http/ngx_http_auth_request_module.html
I compile my nginx as follows: ./configure --with-http_auth_request_module
my code is as follows:
http {
server {
listen 8080 default_server;
server_name _;
location /api {
auth_request /auth;
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location = /auth {
proxy_pass http://localhost:8000/auth/user;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
}
}
my problem is that if my server returns and an error, for example 401, the default page appears. I want to return the json that was returned from my authentication service. it is useless without it. what's the point of showing only a shared page 401? I want to return my json proxy response.
Please, help.