AWS-EC2, how to set multiple public sites with just one instance?

10,905

You can add multiple secondary IP addresses to your EC2 instances inside a VPC - See here: http://aws.typepad.com/aws/2012/07/multiple-ip-addresses-for-ec2-instances-in-a-virtual-private-cloud.html

Then you can attached a public elastic IP addresses to these private IPs. See instructions here: http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-ip-addressing.html#WorkWithEIPs

Then you can use Route 53 (or other DNS service) to point your URL to the IPs of your sites. Here is a link to the getting start with Route 53: http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/GetStarted.html

Update: Once you have your multiple IP you need to point your Domain URL to the different IP. With Route 53 as a distributed and highly available DNS service, you can add these records. See on the documentation about the specific instructions: http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/CreatingNewDNS.html

Share:
10,905
tech_me
Author by

tech_me

IT career since 2006. Platform OS |-Windows, Linux, Mac OS X Lion Cloud |-Public: SasS, PasS, IasS |-Private:Hyper-V, VMware ESXi(vSphere Hypervisor) and others which used in work virtualization Architecture / Framework APP ※All of GIS except data making product. |-Desktop App(VB→.NET)⇒Web Project(ASP.NET, Struts→CakePHP→Symfony)⇒ASP(GIS) Databases |-MySQL, DB2, SQLServer, Sybase, Oracle Other Skills Experienced / Mastered |-GoogleMapsAPI, Some of SNS's API, Ajax(jQuery), MVC, github Interesting |-Virtualization & Cloud, HTML5+CSS3, Smart Phone, RIA

Updated on July 20, 2022

Comments

  • tech_me
    tech_me almost 2 years

    I have read many articles and also topics in SO, but could not find out any further help.

    I have on instance of AWS-EC2, and want to hold several public sites within it.

    I have already get my first public site to run like below:
    http://ec2-50-xxx-214-xxx.us-west-2.compute.amazonaws.com/

    What I have done is just added a file which named manmu under
    /etc/apache2/sites-available

    <VirtualHost *:80>
        ServerName ec2-50-xxx-214-xxx.us-west-2.compute.amazonaws.com
        DocumentRoot /home/ubuntu/manmu/YYYYY/web
        DirectoryIndex index.php
    </VirtualHost>
    

    and then
    ubuntu@ip-10-245-38-136:/etc/apache2/sites-enabled$ ln -s ../sites-available/manmu

    But how could I get my other sites to run?
    For example, I may want some subdomains such as:
    http://abc.ec2-50-xxx-214-xxx.us-west-2.compute.amazonaws.com/
    and so on.

    And also, I could have my local machine to run multiple sites(I mean urls) such as: http://abc.manmu.localhost
    http://def.manmu.localhost
    which I am using /etc/hosts and /etc/apache2/site-availables(and ../site-enabled).
    But I do really not know how to configure AWS for public access of multiple urls.

    I just heard something like Elastic IP, does this any help which instead of a real domain?

    Thank you.
    Best regards,
    tech_me

  • tech_me
    tech_me about 11 years
    Thank you, @Guy. I will have a look later.
  • tech_me
    tech_me about 11 years
    Hi, @Guy. I have read and done something about the former two steps, but don't know how to use the last one about Route 53. Could you give some more hint, please?
  • Guy
    Guy about 11 years
    You wanted to have multiple domains pointing for a set of IPs that are all connected to a single instance.
  • tech_me
    tech_me almost 11 years
    Hi, @Guy. I have been having a busy work for several weeks. Today, I returned to use AWS and find out that I even cloud use different ports for different sites instead of different domains---maybe this is just a basic knowledge of network engineering^^;. Any how, thank you.
  • Bagusflyer
    Bagusflyer over 10 years
    Thanks, is it free or not? (There are only a few users will access my public domain.)
  • Guy
    Guy over 10 years
    Multiple ports doesn't add cost, as you just need to open the ports and define your web container to listen to all ports. If you want to have multiple network interfaces (ENI) and IP addresses it will add a bit to your costs
  • HPWD
    HPWD about 4 years
    @guy I hope you are still around. I am moving from another host in which I had a VPS setup. On the current setup, I had multiple websites (port 80) pointing to a single IP. I made an image of the server and migrated it to AWS. When I spun up the server and pointed my local hosts file to this new server, the first URL I hit will work. Any of my other sites will show the URL I entered but the content from the first site. Since this config worked before, I'm puzzled why it isn't now when the server is literally the same setup.
  • Guy
    Guy about 4 years
    Sounds like a configuration issue. Once you got to your instance through the public_dns and the port, it is only your code and setup. EC2 doesn't change the packages, URL paths, or others. It might be related to moving OS, user/root settings, etc.
  • HPWD
    HPWD about 4 years
    @guy this is my understanding, too, but it's an exact copy of the physical server, only virtualized. Just to cover all the bases though, when you say "public_dns", are you referring to something wtihin AWS or the registrar (aka GoDaddy in this situation)? Right now, I'm managing the connections through a local hosts file with ip www.sampledomain.com.
  • Guy
    Guy about 4 years
    @HPWD every pubic facing EC2 has a public_dns (for example, ec2-203-0-113-25.compute-1.amazonaws.com). You can point other DNS services to point to it. You can also attach a public IP to the EC2 instance, to make this address persistent (the other will change between start/stop actions).
  • HPWD
    HPWD about 4 years
    I attached an elastic IP to the instance since AWS now allows for that (at least I think this is new). I'll keep experimenting to see if I can figure this out and wills start a new SO question (be warned I may tag you) ;) Thank you @Guy!