3

I'm having trouble pointing a domain name to a subdirectory on an Amazon EC2 instance.

FYI - I'm not too experienced with DNS or networking ...

So jumping right in ...

I set up an Amazon EC2 instance with an elastic IP, for example, "1.2.3.4"

Edit: Apache2 server is installed on the instance.

I put a site under a folder, for example, "/var/www/html/website"

I have a domain name, for example, "example.com"

I've set up Route 53 with a hosted zone "example.com" with an A record that points to "1.2.3.4"

So when I go to "example.com", I get the Amazon Test Page.

How would I get "example.com" to point to the "/var/www/html/website" folder

Any help would be appreciated!

Thanks!

Edit: One thing I forgot to mention is that I have other folders for different websites that I want different domain names to point too. Eg. "example.com" points to "/var/www/html/website1" AND "example2.com" points to "/var/www/html/website2"

  • 1
    Valid example websites are example.{com|net|org}, if you want to use those. – TRiG Sep 20 '13 at 15:20
7

I'm assuming you're using the default Apache2 available on EC2's default Amazon distro of Linux... you didn't state, so I don't know for sure. You could be using nginx for all I know, in which case these instructions are wasted.

You need to edit /etc/httpd/httpd.conf or /etc/apache2/apache2.conf (whichever one exists) and change your virtual host configuration. See the Apache reference guide for details. It even has some examples.

Generally, you'll need to remove or repurpose any existing <VirtualHost ... blocks and make sure you have something like this in your config:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
| improve this answer | |
  • The above instruction is correct. I would add- keep your DocumentRoot name and ServerName same. It did not work for me until I renamed so that both matched. – Syed Priom Feb 8 '14 at 22:18
  • 1
    For Amazon Linux, it's /etc/httpd/conf/httpd.conf – Richard Fu Mar 25 '19 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.