Home > Blockchain >  Is possible to route traffic with NGINX (EC2) outside AWS?
Is possible to route traffic with NGINX (EC2) outside AWS?

Time:10-08

I have an infrastructure in a local provider, is about an nginx reverse proxy server and two others server with my node app (prod and test). I have also two subdomains for test: test.mydomain.com and test.mydomain.app

Today, we are moving to AWS as a new provider, and in order to migrate the system by steps, we selected the nginx server first.

I made this:

  • I created an EC2 instance, with the proper security group (http, https and ssh open), under the default vpc - default subnet (including the right route table - internet gateway instance attached)

  • I installed nginx on it and when I go to the Public IP address of the EC2 instance, I see 'Nginx is working!'.

  • I pointed the test.mydomain.app to this new EC2 server

  • I created a test.mydomain.app conf file in the 'sites-available' folder, and then linked with sites-enabled. The content of the block is the following:

     server {
          server_name test.mydomain.app www.test.mydomain.app;
          location / {
              proxy_set_header X-Forwarded-For $remote_addr;
              proxy_set_header Host $http_host;
              proxy_pass "http://XXX.XX.XXX.XXX:3000";
              break;
          }
      }
    

The XXX.XX.XXX.XXX is the Public IP Address of the test server that I have in the local provider right now, and the block that I have there (local provider's nginx) is the same as well.

So, why the nginx from the local provider works well routing the traffic to the test server (that is in the local provider as well) but the nginx from aws can't route the traffic to the same server?

I'm getting ERR_CONNECTION_TIMED_OUT. I tried a lot of ways and got it Connection timeout (but from nginx response sometimes), that's all. I tried also to show a default html and that worked fine, but I need to redirect the traffic to the test server. I also tried to create an NGINX server with the aws lightsail service, but got same result. Can't route traffic outside aws.

I don't know is this is something related to VPC, Networking, nginx or what.

I'll appreciate some help on this, thank you.

CodePudding user response:

I solved it by myself after three days. I'll leave the steps here in case anyone needs them.

  • First, if you are going to route traffic through nginx to an external address, you will need to open the required port in the destiny.
  • Second, you will need to change (probably) the proxy_set_header from $http_host to $proxy_host.

Hope it helps, thanks to Lution on this post

  • Related