Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (12.9k points)

How can I create subdomains on Amazon EC2?

Is adding virtual host in httpd.conf is enough.. or any other changes also needs to be done?


1 Answer

0 votes
by (18.2k points)

It depends on your server software. Since you mentioned httpd.conf, I'm taking it to mean that you run Apache on Linux distribution. If that's true then adding virtual host sure is enough.

One way of doing it is:

1. Get a domain, purchase if you want or get a free domain online ( can be used to get a free domain)

2. Identify the external IP or DNS for your EC2 instance. Associate an Elastic IP with your instance or the IP of your instance will change on reboots.

3. Create a DNS record for your domain

4. Ensure that your httpd.conf contains a line to allow virtual hosts:

nameVirtualHost *:80

5. Create a virtual host directive as shown below:


<VirtualHost *:80>


  ServerAdmin [email protected]

  DocumentRoot /var/www/

  <Directory /var/www/>

    Options Indexes FollowSymLinks MultiViews

    AllowOverride All

    Order allow,deny

    allow from all


  ErrorLog /var/log/apache2/

  LogLevel warn

  CustomLog /var/log/apache2/ combined


6. Restart Apache and you are good to go.

/etc/init.d/apache2 restart

Related questions

0 votes
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
asked Jul 5, 2019 in AWS by yuvraj (19.1k points)
0 votes
1 answer

Browse Categories