Link to home
Start Free TrialLog in
Avatar of student237
student237

asked on

How to setup multiple domains on Amazon AMI EC2 instance.

Hi,
I have setup Amazon-Linux instance on Amazon micro EC2 AMI for php/mysql/apache.

I have created following folder in Apache document root folder.

/var/www/html/domain1/
/var/www/html/domain2/
/var/www/html/domain3/

Now I want to point my three domains : domain1.com, domain2.com and domain3.com to those following folders.

How can I do that? I have some idea that I have to create some DNS server (may be using Amazon 53 router) and put those dns as name server to my domain-register company, correct?

But what else I have to do on Amazon side? I think I have to update httpd.conf file for virtual host file?

Also before taking the dns, can I test that my subdomains are working using ip address for example if my elastic public ip address given by Amazon is 10.10.11.20  then can i check my sub domains using this ip address?
Also what is difference between subdomain and add-on domain?

Do I need a CPnel if I want to load 5 - 6 domains of my own?

Thanks.
Avatar of arnold
arnold
Flag of United States of America image

If you are comfortable with editing the /etc/HTTPd/conf.d or /etc/apache2/cond.d by creating a file that contains the virtualhost definition with servername and document root you do not need cpanel, cpanel simplifies management of a domain/user emails if any etc to a central UI ........

No, what you could do to your virtualhost entry add a line such as
serveralias test.domain1.com
Then on domain1.com DNS zone add a host test1.domain1.com pointing to the public IP of your server. Then use a browser to access test1.domain.com.........
Avatar of student237
student237

ASKER

Thanks for your reply. I understand cpanel now and I think, I don't need it.
Now to make subdomain or add-on domain are the following steps are correct:
(Note: my main objective is that if i input domain1.com then it should map to domain1.com.10.10.11.20\index.html )

1.
mkdir /var/www/html/domain1_folder
mkdir /var/www/html/domain2_folder
mkdir /var/www/html/domain3_folder

2. Add following entry into /etc/httpd/conf/httpd.conf

<VirtualHost *:80>
ServerAdmin webmaster@domain1.com
DocumentRoot "/var/www/html/domain1_folder"
ServerName domain1.com
ErrorLog "logs/domain1.com-error_log"
CustomLog "logs/domain1.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@domain2.com
DocumentRoot "/var/www/html/domain2_folder"
ServerName domain2.com
ErrorLog "logs/domain2.com-error_log"
CustomLog "logs/domain2.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@domain3.com
DocumentRoot "/var/www/html/domain3_folder"
ServerName domain3.com
ErrorLog "logs/domain3.com-error_log"
CustomLog "logs/domain3.com-access_log" common
</VirtualHost>

3. Now as http://10.10.11.20/ this work or accebile
So can I access
http://domain1.10.10.11.20/
http://domain2.10.10.11.20/
http://domain3.10.10.11.20/

is there any missing thing except DNS name server which I am thinking of using Amazon 53 router.
One thing, you should not be editing/adding entries to HTTPd.conf

Look at the bottom of HTTPd.conf, there should be an include directive pointing to conf.d/*.conf
Add the virtualhost in individual files domain1.conf then copy the one to the others and then edit the contents to match.

<VirtualHost *:80>
ServerAdmin webmaster@domain1.com
DocumentRoot "/var/www/html/domain1_folder"
ServerName domain1.com
ServerAlias www.domain1.com
serverAlias test.domain1.com
ErrorLog "logs/domain1.com-error_log"
CustomLog "logs/domain1.com-access_log" common
</VirtualHost>

Open in new window

You may want to document reference dealing with the search index.html, index.htm, I decided.php, etc.

10.x.x.x is not a routeable ip,

If you do not want to alter domain1.com DNS revord, you can make the adjustment in your workstation's hosts file
X.x.x.x www.domain1.com
Once you save the entry www.domain1.com on this workstation will be directed to x.x.x.x.
Ps, placing the domain1-folder in the HTML folder, it means it can be accessed without the virtualhost http://x.x.x.x/domain1-folder
Note if you do not go through the virtualhost path and your site has explicit oaths for www.domain1.com some links will bounce out to the current host/site.
Ohh now sound complicated.. :)
Does CPanel do all things automatically? I think I need now cpanel, I am not much expert of Linux.  I am a developer and want to develop and manage Magento or wordpress/blog sites. I want to keep things as simple as possible.

Is configuration of CPanel is simple or complicated?

Regards,
Can you refer me step by step type document to setup CPanel or multiple domains as subdomains/add-on domain.
While something sounds complicated, the setup is a one time thing.

Setup is a one/two step deal and is not something that is ongoing.
Yes cpanel makes it simpler, I.e. It has a GUI view of your system's categories of configuration.

There is a FAQ from the vendor of cpanel.
Usually if it is installed, it would be accessible as http://www.yourdomain.com/admin or cpanel.


Different providers have different ways to deploy/provide cpanel to their customers.  I believe cpanel is a commercial product such that my advice would be to first check with Amazon on getting cpanel on your box if not available already.
Cpanel info generally http://www.cpanel.com.
Just copy the code I posted and place it in /etc/HTTPd/conf.d as domain1_com.conf

Oh, not sure which part of the long comment makes it complicated? The configuration of Apache on the server,
Or the two ways of accessing it prior to making the new location live.
If it is one time setup then it is ok, I will try. Lets start from beginning.
I have added two config files in /etc/httpd/conf/

sudo nano domain1.conf

<VirtualHost *:80>
ServerAdmin webmaster@domain1.com
DocumentRoot "/var/www/html/domain1_folder"
ServerName domain1.com
ServerAlias www.domain1.com
serverAlias test.domain1.com
ErrorLog "logs/domain1.com-error_log"
CustomLog "logs/domain1.com-access_log" common
</VirtualHost>

sudo nano domain2.conf

<VirtualHost *:80>
ServerAdmin webmaster@domain2.com
DocumentRoot "/var/www/html/domain2_folder"
ServerName domain2.com
ServerAlias www.domain2.com
serverAlias test.domain2.com
ErrorLog "logs/domain2.com-error_log"
CustomLog "logs/domain2.com-access_log" common
</VirtualHost>


Question 1. Should I take Amazon 53 to point to my main website to server ip 10.10.11.20?
Question 2. httpd.conf has line
'IncludeOptional conf.d/*.conf'
at the bottom. Do I need to add any other line or ref. or it will automatically load all *.conf files?
Question 3: How to make index.php or index.html by default to come?
Question 4: You said that I can adjust my workstation's hosts file ? do you mean amazon ec2 server or my laptop ?
I tried to http://domain1.com.10.10.11.20/index.html it is not comming:

Following error message:

The server at domain1.com.10.10.11.20 can't be found, because the DNS lookup failed. DNS is the network service that translates a website's name to its Internet address. This error is most often caused by having no connection to the Internet or a misconfigured network. It can also be caused by an unresponsive DNS server or a firewall preventing Google Chrome from accessing the network.
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial