0

How one is able to proxy the requests (or the API calls) of an Angular app hosted on Nginx towards backend running on a docker container having another port value (the Angular app is also dokcerized)?

Currently, I have an nginx.conf file and copying it to /etc/nginx/conf.d/default.conf, but cannot get the results from the backend. This is nginx.conf file:

server {
   listen 80;
   server_name localhost;

   root /usr/share/nginx/html;
   index index.html index.htm;

   location / {
      try_files $uri $uri/ /index.html = 404;
    }

    location /api/ {
       proxy_pass http://0.0.0.0:8080/api/;

    }

}
5
  • What is the problem you are having? Jul 3, 2020 at 17:57
  • @MichaelHampton thanks for your reply. So, I am not able to proxy the requests into the backend application (which is also running as a docker container, and only having access to its image - so running withing the same machine locally, i.e. within the same docker host). For example, when there is an API call (say get all...), I do not see the requests getting into the proxy call, and such that getting the " net::ERR_CONNECTION_REFUSED". And, when I see the HttpErrorResponse, the url is only set as :{..., url: " /api",...}.
    – Leo
    Jul 4, 2020 at 8:30
  • 1
    You need to use the address of the Docker container instead of 0.0.0.0 in your proxy_pass directive. Jul 5, 2020 at 18:39
  • @TeroKilkanen thanks for your message. Yes, I used it - I used the container name instead of 0.0.0.0, but still cannot get it work. I receive 502 bad gateway error.
    – Leo
    Jul 5, 2020 at 23:58
  • You nned to use the container id. Nov 17, 2020 at 8:25

0

You must log in to answer this question.

Browse other questions tagged .