Creating Subdomains in Amazon Ec2

Creating subdomains in Amazon EC2

Depends on your server software. But as you mention httpd.conf, chances are good that you run Apache on a Linux distribution. If that's the case then yes, adding a virtual host is enough. Here is one way of doing it:

  1. Purchase a domain. If you have one, skip this, we'll take example.com for this example.
  2. Find the external IP or DNS for your EC2 instance. You probably want to associate an Elastic IP to your instance, otherwise the IP of your instance will change on reboots.
  3. Create a DNS record for your domain, for instance a CNAME record to point to your Elastic IP/DNS name:

    subdomain.example.com => ec2-xx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com

  4. Make sure your httpd.conf contains a line to allow virtual hosts:

    NameVirtualHost *:80

  5. Create a virtual host directive:

httpd.conf:

<VirtualHost *:80>
ServerName subdomain.example.com
ServerAdmin webmaster@subdomain.example.com

DocumentRoot /var/www/example.com/subdomain

<Directory /var/www/example.com/subdomain>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ErrorLog /var/log/apache2/subdomain.example.com.error.log
LogLevel warn
CustomLog /var/log/apache2/subdomain.example.com.access.log combined
</VirtualHost>

6. Restart Apache

/etc/init.d/apache2 restart

How to manage multiple subdomains with Amazon EC2?


do I now have to create and manage the subdomains on the Amazon server
or at GoDaddy?

You need to create each subdomain at your DNS service (Godaddy) and point each of those subdomains to your Elastic IP. On the AWS side you will need to configure the web server running on EC2 with the knowledge of each of those subdomains, and what content it needs to serve for each of them.

what's the advantage between an Amazon route 53 hosted zone and just
pointing the domain to the Elastic IP?

There are certain AWS services like Elastic Load Balancers and S3 static websites that do not provide an IP address, only a domain name. To map the root of your domain to one of those services you would have to use Route53 alias records. Route53 also offers features like health checks, failover routing, latency routing, etc. Other than that, there isn't really any advantage to Route53 versus another DNS service like GoDaddy.

How to create subdomain on Amazon EC2?


  1. The CNAME record needs to be created in the DNS hosting your domain. You will need to do this with your DNS provider, typically not in the nameserver (bind) on your Ubuntu machine.

  2. NameVirtualHost is not needed anymore for Apache 2.4, yes. It was used before to instruct the server that a particular IP address and port combination was usable as a name-based virtual host. Nowadays, is sufficient.

  3. You can put the statements into any (new) file in sites-available and link that new file in sites-enabled, or create a new httpd.conf. All of that should work.

  4. Where to store the subdomain is entirely up to you and how you would like to structure your setup on your disk.

I hope this helps.

Managing a subdomain on AWS with R53 and EC2

You say that you installed a LAMP stack on the instance, so presumably there is a web server listening on port 80.

To test this, first login to the instance via SSH, then try curl localhost to test the web server. If that fails, then there is a problem with your web server.

If it works, the you should check the Security Group associated with the Amazon EC2 instance. It should be allowing incoming traffic on port 80 from 0.0.0.0/0.

Next, obtain the Public IP address of the instance. In a browser on your own computer, try accessing the IP address, eg http://1.2.3.4. That should work if the Security Group has been correctly configured.

By the way, you should be using an Elastic IP address (EIP) for the EC2 instance, which is a 'static' IP address that does not change. You can create an EIP in the EC2 management console, then associate it with the instance. This prevents the Public IP address from changing if the instance is stopped.

Next, try accessing the instance via the domain name. If this does not work, then test the name resolution by using ping with your domain name. The Ping itself won't work, but it should display the IP address that is linked to that domain name. Make sure that the IP address matches the Public IP address you used in the previous step.

If no IP address is provided, then you are missing an A-Record in the hosted zone. You should create the A-Record in the hosted zone and provide it with the Public IP address of the instance.

HTTPS setup for subdomain in Amazon EC2


Amazon Certificate Manager and tried setting up the route 53 cname record for api.example.com to point to the EC2 instance public IP.

ACM certificates can't be used on instances, but only with ELB, CF distro and API gateway. So you should use an SSL certificate (not self-signed) from a third party on your instance. You correctly tried with nginx - certbot combo, which is the correct way of doing this. Thus, I would look into why the nginx - certbot does not work, especially as you have already your own domain for it.

Use Subdomain with Amazon EC2 Public DNS Address?

Why are you not using your own domain name? Most web services based on EC2 do not use the EC2 public DNS, because that public DNS is likely to change.

What you probably want to investigate is using Elastic IP's so as to give your instances stable IP addresses that you can configure DNS against, then attach these Elastic IP's to your EC2 instances.

Here is the AWS documentation on Elastic IP's: http://aws.amazon.com/articles/1346

Of course, if you plan on using a load balanced configuration, then you would actually use Elastic Load Balancer rather than Elastic IP's. In this configuration, your DNS would direct to the ELB.

Here is information on Elastic Load Balancing: http://aws.amazon.com/elasticloadbalancing/



Related Topics



Leave a reply



Submit