Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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?

Thanks

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 ( freenom.com 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:

httpd.conf:

<VirtualHost *:80>

  ServerName subdomain.example.com

  ServerAdmin [email protected]

  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 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

...