0 votes
1 view
in AWS by (9.2k 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.5k 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...