How to point domain name to Amazon EC2 subdirectory

3

4

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"

Mr. Meeseeks

Posted 2013-09-20T14:52:22.730

Reputation: 153

1Valid example websites are example.{com|net|org}, if you want to use those. – TRiG – 2013-09-20T15:20:20.080

Answers

6

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>

allquixotic

Posted 2013-09-20T14:52:22.730

Reputation: 32 256

For Amazon Linux, it's /etc/httpd/conf/httpd.conf – Richard Fu – 2019-03-25T08:56:11.533

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 – 2014-02-08T22:18:30.023