Monday, October 12, 2015

Setting up a domain on Amazon Web Services EC2


we have a new Amazon Web Services EC2 server fully configured as a webserver, let’s point a domain to it, as this has it’s own idiosyncrasy using the AWS system.
Setting up AWS to provide an IP address for your DNS settings
  • First we will need to assign an IP address to our server using Amazon’s Elastic IP system, so click Elastic IP’s in the left hand menu.
  • In the top menu under “Addresses”, click “Allocate New Address”.
  • Ensure “EIP used in” is set to “EC2″ and click “Yes, Allocate”.
  • Click the tick box next to the new IP address that has appeared in the main left pane and press the “Associate Address” button in the top menu.
  • In the “Instance” drop down, select your webserver that we set up previously and click “Yes, Associate”.
  • That’s it for management on the AWS side of things, however please note that now when accessing your webserver through SSH, SFTP or MySQL, your public DNS address that you were using for the connection will have changed. At this point it is probably better to just use the new IP address to connect that you have just associated with your webserver.
Setting up your DNS
  • We won’t go into too much detail here as there are far too many domain and DNS providers (GoDaddy, 123-Reg to name a couple) to cover off every eventuality, just ensure that the IP address you have created in AWS Management is entered for the @ and www records for your domain.
Setting up some VirtualHosts
  • You may want to set up more than one domain on the server, so let’s set up a VirtualHost to show the way to do this on an EC2 instance.
  • Your default webserver configuration after going through the previous steps should load additional configuration files from the “conf.d” directory, so let’s switch to it with the command “cd /etc/httpd/conf.d”.
  • Type “sudo su” and hit enter to give us all the privileges we might require.
  • Type “vi httpd-vhosts.conf” and hit enter. This will create a new file where we will store the virtual hosts information.
  • Press “i” to enter insert mode and type the following, replacing your-server.com with the domain name you want to use:
1
2
3
4
5
6
7
NameVirtualHost *:80
 
<VirtualHost *:80>
        ServerName www.your-server.com
        ServerAlias your-server.com *.your-server.com
        DocumentRoot /var/www/html/your-server.com
</VirtualHost>
  • Press escape, then type “:wq!” to exit the editor.
  • This tells the apache server to look in the /var/www/html/your-server.com directory for the files for any request to the your-server.com domain.
  • Let’s check that the rules you’ve typed in are working correctly by typing “httpd -S”, this should tell you that the syntax is ok.
  • Finally, we just need to restart Apache to get it to take notice of the new configuration file. Type “apachectl restart”.
  • And you’re done! Type your domain name into your browser and you should see the files from the appropriate directory!

No comments:

Post a Comment

Dharamart.blogspot.in