How to host multiple domains and subdomains on single AWS EC2 instance - apache

I am trying to set up 2 domains (domain1.com and domain2.com) with a few subdomains (app.domain1.com) in AWS and run them on single instance (Amazon Linux, PHP, MySQL).
I have set up 3 hosted zones in AWS Route53 with following configurations.
Hosted zone 1:
domain1.com
Type A
52.108.XX.YY
Hosted Zone 2
domain2.com
Type A
52.108.XX.YY
Hosted Zone 3
app.domain1.com
Type A
52.108.XX.YY
Additionally, I have added following code to the http.conf file in VirtualHost tag.
<VirtualHost *:80>
ServerName domain1.com
DocumentRoot "/var/www/html/domain1"
ErrorLog "logs/domain1-error_log"
CustomLog "logs/domain1-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName domain2.com
DocumentRoot "/var/www/html/domain2"
ErrorLog "logs/domain2-error_log"
CustomLog "logs/domain2-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName app.domain1.com
DocumentRoot "/var/www/html/app"
ErrorLog "logs/app.domain1-error_log"
CustomLog "logs/app.domain1-access_log" common
</VirtualHost>
However, only domain1.com and domain2.com are getting resolved. When I visit app.domain1.com, it gives me a "can't find server" error. Please help how to setup the subdomain - is there problem in Hosted Zone setup or httpd.conf?

Ok, so after about 2 hours of reading up various sites and tinkering, I am all set. Here is how to do this.
Basically, you should not have more than 1 hosted zone (HZ) per domain name, otherwise things are really going to be bad. If you have more than 1 HZ for a domain name, please delete the one that was created for the subdomain.
Each HZ will have 4 records -
Following two records are created by default. Do not edit/delete them.
NS - This is the name server record. If AWS Route53 is not your registrar, use ns-servernumber.awsdns-number.com. and other three (4 total) records to change name servers for your registrar.
SOA - Let this record be. DO NOT TOUCH THIS.
Create following two Record Set (blue button).
A - Leave Name blank. Select A-IPv4 address for Type. In Value enter the IP address for your Elastic Load Balancer or EC2 instance.
CNAME - Add * (asterisks/wildcard) in the name field. Select CNAME from the drop down for Type In Value enter the domain name.
Now create the http.conf file and structure virtual hosts like I have in the question.
Things should work now :)

You can follow the tutorial on this link: http://brianshim.com/webtricks/host-multiple-sites-amazon-ec2/
A common error, according to the link, is:
Did it work? If not, here is one possible cause. There might be
another configuration file interfering with this one. Check for
another .conf file in /etc/httpd/conf.d. Often your primary
httpd.conf will include another .conf file in this directory. Make
sure it doesn’t have some Virtual Host settings which are interfering
with yours.
After you set the configurations, you should run:
sudo service httpd restart

This can be done installing Apache HTTP Server on AWS-EC2 instance and configuring VirtualHost for each DNS or Sub-DNS as suggested by an Amazonian
For brevity read this thread discussion, this official example and techrepublic post.
Hope this helped!

Related

Accessing Virtual Hosts Across a Local Network

I've 2 machine on my local network. On my first machine A, i've creat a vhost mysite.lan and i want access to this vhost with my machine B.
If i don't edit my host file, i do not access.
Do you know if i can access on my vhost without edit my host file ?
My vhost :
<VirtualHost *:80>
ServerName wordpress.lan
ServerAlias www.wordpress.lan
DocumentRoot /var/www/html/www.wordpress.lan/webroot/
ErrorLog /var/www/html/www.wordpress.lan/logs/error.log
CustomLog /var/www/html/www.wordpress.lan/logs/access.log combined
</VirtualHost>
Thank you !
You'll need something on your network to read these requests and forward them to the correct address - in the absence of anything else an entry in the hosts file will do this.
Your router contains DNS servers, either entered manually or populated by your internet service provider. By default, these servers provide lookup information for DNS queries. You can run a DNS server locally, but it's a lot of work to achieve what you're looking for.
See this link for info on doing this on Linux (I'm not sure what OS you're on, but I assume it's either Mac or Linux based on format of your vhost entry):
https://superuser.com/questions/45789/running-dns-locally-for-home-network

virtualhost keeps redirecting to deleted alias information

I have a DigitalOcean droplet (i.e. a VPS server), with Ubuntu 14.04 and Apache 2.2.
I had 4 virtualhosts configured, with 4 different domains pointing to 4 different folders, no problem.
I needed to point a 5th domain (let's call it www.someshop.tld) containing a PrestaShop installation.
I added the following Alias to the apache2/sites-available/domain1.conf file so that www.domain1.tld/someshop would lead to www/prestashop, and it worked fine
<VirtualHost *:80>
ServerName www.domain1.tld
DocumentRoot /www/directory1
Alias /someshop /www/prestashop #Alias line
</VirtualHost>
I did this as a temporary measure so I could have a working site publicly accessible, (so I could access www/prestashop publicly before I had configured www.someshop.tld DNS settings, 'A' record, Nameservers, etc.).
I now don't need to do this any more, so I deleted the Alias line from the .conf file so it looks like this:
<VirtualHost *:80>
ServerName www.domain1.tld
DocumentRoot /www/directory1
</VirtualHost>
and added a new someshop.conf that looks like this:
<VirtualHost *:80>
ServerName www.someshop.tld
DocumentRoot /www/prestashop
</VirtualHost>
I then re-enabled both the .conf files in apache2/sites-enabled, and restarted apache with service apache2 restart.
However, when I go to www.someshop.tld, it continues to do a URL redirect to www.domain1.tld/prestashop (where there's this message: "Not Found, The requested URL /someshop was not found on this server").
I waited for a couple of hours before posting this question because I thought it might just be a "propagation" issue. So far it's still doing this.
My question: is this something that should clear up by waiting for it, or do I need to fix something else? E.g., is there some way for me to flush the old virtualhost Alias information?
Have you tried removing the site from apache config?
$ sudo a2dissite test.com.conf #Remove symlink
$ sudo service apache2 reload
This would remove the symlink. You can then create the symlink again with the proper configurations that you like.

How properly set a website and domain (with subdomains) with apache on ubuntu?

First of all, apologies for my English.
I've been reading and reading guides last week a lot hours with no success. I bought a domain + hosting but due bad performance I've got a cheap vps to use as hosting. Currently my setup is:
A domain .com with an A record pointed to my vps ip.
A unmanaged vps with Ubuntu 14.04.2 64 bits to use as hosting for my wordpress with LAMP stack with default setup (I didn't changed any setting on apache, using default virtualhost).
My site works fine but I'm don't know how create subdomains with different directories. For example, my website.com files are in /var/www/html and I'd like to create subdomain.website.com with the files in other directory, let's say /var/www/subdomain.
I checked a lot tutorials and they say to create a virtual server on apache (I use webmin) and then an A record for the subdomain pointing to the server ip.
The problem is that when I enter to subdomain.website.com I see the content from main domain (/var/www/html) and not from "/var/www/subdomain"
I don't want ask you for a full guide step by step, I just need know where I need to start for achieve a subdomain with a different directory because usually I always used hosting services with tools like cpanel to create subdomains pointed to directories in 2 clicks.
I'm a full newbie with Apache/dns management.
Thanks a lot for your time!
Create a virtual host in Apache by creating a file at /etc/apache2/sites-available/subdomain.website.com.conf
In that file, add the following
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName subdomain.website.com
DocumentRoot /var/www/subdomain.website.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now place your subdomain.website.com files at
/var/www/subdomain.website.com/public_html
Then enable the new virtual host by sudo a2ensite subdomain.website.com
After placing the files, if you get a 403 forbidden error, check for permissions of the DocumentRoot folder.
Refer: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

Multiple domain names on a single server

Sorry my English
I have Ubuntu 12.04 openVZ VPS, with Apache and Passenger installed, to run Ruby site. That site have several faces which available (not yet) from different domains. In /etc/apache2/sites-available I created file site1.com which contains this:
<VirtualHost *:80>
ServerName site1.com
DocumentRoot /home/happy_buddha/Sites/rubysite/public
<Directory /home/happy_buddha/Sites/rubysite/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Previously I created A record on site1.com domain which contains server's ip.
Now if I going to site1.com browser's window contains this:
What I'm doing wrong?
you can not give virtual host name same as other's.
Like you said " I created A record on site1.com domain which contains server's ip." then you have to change your virtual host's name. Try with different name. for eg site2.com or site1.local
Make sure that you have NameVirutalHost *:80 set in your apache config - this will probably be in /etc/apache2/ports.conf on your Ubuntu server.
It sounds like the new site you created is acting as the default virtual host which is why you can't see the site you had before.
That said, if you actually visit site1.com, then I might expect to see the result you get, I don't know where the config is done for interpreting the ruby code but this might need to be part of the VirtualHost too.

Creating subdomain on Amazon EC2 does not works

I want to create a subdomain from a real, living site which I will call example.com. The subdomain has to be named subdomain.example.com. Everything is running on a Amazon EC2 instance.
I just can't access the subdomain.example.com, when trying to access this URL, the browser shows the usual "Server not found" message.
I followed the next steps (includes steps from other StackOverflow answers):
1.-Acquired the domain example.com at GoDaddy.
2.-Linked correctly the example.com website to the real server, so the main site works fine.
3.-Went to the Amazon EC2 Console and created a EIP (Elastic IP)
4.-Went to Route53 and added a new Hosted Zone just like this article says (http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/CreatingNewSubdomain.html)
So that at I can see the subdomain.example.com Hosted Zone, and inside it there is a A Record that points to my Elastic IP.
5.-Went to the server and checked that the line "NameVirtualHost *:80" is there.
6.-Created a Virtual Host directive like the next one:
<VirtualHost *:80>
ServerName subdomain.example.com
ServerAdmin webmaster#subdomain.example.com
DocumentRoot /opt/bitnami/frameworks/codeigniter/htdocs
<Directory /opt/bitnami/frameworks/codeigniter/htdocs>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/subdomain.example.com.log
LogLevel warn
CustomLog /var/log/apache2/subdomain.example.com.access.log combined
</VirtualHost>
7.- Restarted the apache server
However, as stated at the start of the post, I can't ping or access the website.
What step could I be missing?
Are there chances that the change hasn't been propagraget yet? One day after the subdomain creation I'm still unable to access the website.
Ok, thanks to #Sergey and #datasage, the updated step list:
4.1- Go to your GoDaddy account (or your alternate provider) and add the 4 addresses obtained from Route 53 Hosted Zones, these addresses are under the label "Delegation Set".
4.2- Wait for about an hour until the changes are done (in my case it worked instantly for some reason)
Here is an useful article about these steps: http://blog.sefindustries.com/redirect-a-subdomain-to-route-53-from-godaddy/
Check subdomain.example.com, if record exists in DNS or propagated well:
Ask you default "home" DNS server
dig -t A subdomain.example.com
Ask google dns
dig -t A subdomain.example.com #8.8.8.8
Ask your authorized DNS server
dig -t A subdomain.example.com #your.ns.server
In case of windows use nslookup
or
Use internet service (for example digweb)