This is the schematic of my microservices setup:
To put in words:
- request comes from browser
- nginx reverses proxy the request to the angular container
- angular container makes request to the backend service to retrieve data
Now my backend service is protected and can be accessed only with an Authorization header which is generated in the backend itself when hitting /login.
If the login is successful, angular will take the token and attach it to every subsequent request to the server. Only that it doesn't happen.
As you can see the Authorization header is not embedded into the request therefore the backend service will never receive it and throwing a 401.
This is my angular nginx full setup:
server {
listen 4200;
location / {
proxy_pass_request_headers on;
proxy_pass_header Authorization;
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}
whilst this is the nginx reverse proxy
location /myne-dashboard-webui/ {
proxy_pass http://myne-dashboard-webui/;
proxy_pass_request_headers on;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass_header Authorization;
}
I have tried to use proxy_pass_header, set_header $http_request and add_header, but all failed. Can anyone help? Thank you in advance
Edit: Furthermore, if I run my angular application and the backend standalone, wo without nginx and docker then it works as expected, so I rule out the possibility that one of my services are wrong