1

I do have a complex scenerio. I have two AWS instances.

Instance 1: Running Nginx         (have 1 private IP, 1 public IP)
Instance 2: Running Nodejs server  (have 1 Private IP only, NO PUBLIC IP)

Here is what I am trying to do. I have a redirect setting in my nginx config which forwards the requrest for a particular URL to Instance 2.

It works fine when I try browsing from http://Instance 1's private IP, but it does not work if I try by browsing from http://Instance 1's public IP.

I am using nginx reverse proxy setting. It works great when URL is browsed via private IPs but does not when it is browsed via public IP.

What I might be doing wrong? or this something that is not supported?

Regards Aun

Aun Raza
  • 31
  • 1
  • 4
  • Possible duplicate of [Node.js + Nginx - What now?](https://stackoverflow.com/questions/5009324/node-js-nginx-what-now) – Derek Brown Oct 11 '17 at 17:15
  • both servers in above mentioned link as on same private IP. Nginx should work just fine in this case. If you read my question carefully, nginx works fine on private Ip to node server. it is not working via public IP – Aun Raza Oct 11 '17 at 17:43

1 Answers1

0

Simply "redirecting" an HTTP request to the private IP address would not work, as the private IP is not routeable from hosts outside that private network.

What I think you are looking for is Nginx's reverse proxy functionality. There is a good guide on how to set that up here.

Derek Brown
  • 4,232
  • 4
  • 27
  • 44
  • It is working fine via private Ips of both servers. Instance1's public IP should be able to redirect the URL to Instance2's private IP (that the issue we are looking fix for). – Aun Raza Oct 11 '17 at 17:45
  • @AunRaza how are your EC2 security groups configured? Have you opened port 80? – Derek Brown Oct 11 '17 at 17:52
  • yes it is . It is working on private IP just fine over port 80. I have 80 and 443 ports enabled over aws security group. – Aun Raza Oct 11 '17 at 19:27
  • @AunRaza what origins are you allowing? – Derek Brown Oct 11 '17 at 21:59
  • The EC2 network topology doesn't associate the public ip with the nginx instance- rather, it translates the public ip to a private one. Thus internal traffic over the public ip is indistinguishable from public traffic. – Derek Brown Oct 11 '17 at 22:01