2

I have my angular app installed at nginx on my ip ,so whenever I put my ip xx.xxx.xxx in browser static content of my angular app is served ,Now I want to have the reverse proxy for the same ip as load balancer to my backend node app server

My configuration

upstream app_servers {
    server 127.0.0.1:3900;
    server 127.0.0.1:3901;
    server 127.0.0.1:3902;
    server 127.0.0.1:3903;
}

server {
    listen 80;
    server_name xx.xxx.xxx; // ip
    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://app_servers;
    }
}

Now if use above configuration my load balance works properly but my angular app doesn't gets delivered .Any idea how to do both simultaneously .I know I can giver different server name ,but any idea to do this with only ip ,currently I dont have and domain.

Thanks

gANDALF
  • 360
  • 4
  • 21
  • Add another server block with another server_name. Probably use `api.yourapp.com` for node backend and `yourapp.com` for angular app. – MjZac Apr 19 '20 at 17:00
  • I dnt have domains ,so will these dummy names gonna work? – gANDALF Apr 19 '20 at 17:02
  • No. But you could something else like, serve html/ css/ js file requests from a folder using regex in `location` block. Serve other requests using node backend. https://stackoverflow.com/a/23780906/2861108 – MjZac Apr 19 '20 at 17:05
  • Another option would be to combine the node backend and build of angular app and serve it as a single application. So angular app will load on say a url `/my-app` – MjZac Apr 19 '20 at 17:09
  • Do the two applications have a well defined URI namespace? In which case you need two or more location blocks to split the traffic between static and proxy. Otherwise, Nginx will need to check every URI for a static file and proxy only when a file is not found. – Richard Smith Apr 19 '20 at 17:20
  • umm not really i just have an ip ,can you bit more elaborative @RichardSmith any example may be – gANDALF Apr 19 '20 at 17:43
  • See [this answer](https://stackoverflow.com/questions/51492495/nginx-how-can-i-serve-my-static-content-with-https-that-has-a-proxy-in-location/51497749#51497749). – Richard Smith Apr 19 '20 at 18:07
  • Were you able to resolve this? – pregmatch May 26 '22 at 12:03

0 Answers0