1

I'm using a default EC2 instance with no domain name registered. I'm attempting to test some multi-tenant functionality in a MEAN stack app using subdomains.

Basically I can access the site through the browser using a default AWS public DNS ex.

http://ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com

That's all good and fine, it works OK.

The problem is that I want to enable the ability to access subdomains of that domain. So for example I want to be able to hit:

http://client1.ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com
http://client2.ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com
etc.

I can't figure out how to do this using nginx. Here's my current nginx default file:

server {
        listen 80;

        server_name *.ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com;

        location / {
                proxy_pass http://127.0.0.1:8080/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }
}

However when I navigate to any subdomain I get an error saying the webpage is not available.

If I access it without a subdomain the page loads just fine.

Any ideas on how I can get this to work?

Appreciate any help!

EDIT: You will notice that I've created a proxy pass because I have my node server running using forever on port 8080.

harbinja
  • 918
  • 8
  • 15

2 Answers2

1

You can't do this with the default amazonaws hostname, but there is another way.

See http://xip.io.

any.subdomain.you-like.x.x.x.x.xip.io will automatically resolve to the IP address x.x.x.x, so if you substitute your EC2 instance's IP address in the hostname, you have what you need, here.

For clarity: I'm not affiliated with this service.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
0

As far as I know, Amazon does not create wildcard records for their EC2 domains, so the *. addresses aren't even going to resolve (you can easily test this). You would instead need to register a domain and have it wildcarded as a CNAME to your EC2 instance.

Joshua DeWald
  • 3,079
  • 20
  • 16