Nginx reverse proxy configuration
upstream frontend {
server frontend:4200;
}
upstream backend {
server backend:4000;
}
server {
listen 80;
location / {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://frontend;
}
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://backend;
}
}
I have a nginx which works as a reverse proxy for my app. I use Bearer token for user authentication between frontend and backend. When I set auth_basic in nginx - it's conflicts with my Bearer app auth as nginx could not have 2 Authentication headers. Are there any solutions on how to restrict access to my env and in the meantime continue to use Bearer token in APP? PS: backend is written in NodeJS (NestJS)
/api/validate_tokenand using it within the internal authentication location defined by theauth_requestdirective viaproxy_pass .... However, when you programmatically add anAuthorization: Bearer ...header to your API call, the browser won’t include anAuthorization: Basic ...header, ensuring that nginx receives only oneAuthorization: ...header. And if all your API endpoints are protected with Bearer authentication while your frontend is secured with Basic authentication, why bother going further?