0

This is the schematic of my microservices setup:

enter image description here

To put in words:

  1. request comes from browser
  2. nginx reverses proxy the request to the angular container
  3. 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.

enter image description here

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.

enter image description here

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 enter image description here

user3353167
  • 101
  • 1
  • Why are you looking at nginx? The problem seems to be in your frontend. – Michael Hampton Nov 18 '20 at 15:44
  • Hey @MichaelHampton I'm not sure about that because if I run it in my local it works as expected – user3353167 Nov 18 '20 at 15:50
  • You show it not working on localhost! And nginx has nothing to do with your frontend code anyway. – Michael Hampton Nov 18 '20 at 15:56
  • Hey @MichaelHampton, this is all inside nginx and docker. If I run my angular app and my server separately without the help of nginx or docker it will run fine. Thus my hypothesis that somehow nginx is not behaving properly – user3353167 Nov 18 '20 at 16:16
  • @MichaelHampton to convince you, I tested and edited the question with a screenshot of the request working as expected outside of nginx and docker – user3353167 Nov 18 '20 at 16:46

0 Answers0