I'm experiencing a problem with an unintentional redirect between two virtual hosts. I'm pretty sure it's a simple configuration error, but as often happens I'm having trouble seeing my own mistake.
Details: Running Apache2 on Ubuntu 14.04 LTS.
I have three named virtual hosts specified in sites-available.
Two of the hosts work as expected: entering the domain name (hostname1.com or hostname2.com) in the address bar of a browser opens the correct file from /var/www/host_name1/public_html or /var/www/host_name2/public_html.
However, entering the third domain name (host_name3.com) in the browser address bar opens host_name2.com, showing the index file in /var/www/host_name2/public_html. Oddly, entering host_name3.com/index.html in the browser results in the correct page from /var/www/host_name3.com/public_html being shown.
I have checked the virtual host files and they appear (to me) to be correct:
Host_name1.com.conf
ServerAdmin admin#host_name1.com
ServerName host_name1.com
ServerAlias www.host_name1.com
DocumentRoot /var/www/host_name1.com/public_html
Host_name2.com.conf
ServerAdmin admin#host_name2.com
ServerName host_name2.com
ServerAlias www.host_name2.com
DocumentRoot /var/www/host_name2.com/public_html
Host_name3.com.conf
ServerAdmin admin#host_name3.com
ServerName host_name3.com
ServerAlias www.host_name3.com
DocumentRoot /var/www/host_name3.com/public_html
This all looks correct to me. DNS seems to be working as expected... DiG returns the correct domain/IP info for all three domain names. Apache logs don't see to show anything out of the ordinary.
Anyone willing to make a guess as to what I've incorrectly configured, point me to somewhere to look for a mistake that has this as its symptom, or otherwise help me figure this out?
Thanks,
Dan
Related
I know that I can have multiple websites hosted on the same EC2 box. The way I'm doing it is pointing Route 53 for the domain to the same box and in my httpd.conf file I'm adding something like this:
<VirtualHost *:80>
ServerName mywebsite.com
DocumentRoot "/var/www/html/website1"
</VirtualHost>
This works great for websites that have an assigned domain name.
What if I am still working on a site/application and don't have a domain name assigned to it?
<VirtualHost *:80>
ServerName <==what goes here if I don't have a domain name yet?
DocumentRoot "/var/www/html/website2"
</VirtualHost>
Is this even possible?
I tried just taking the IP of the box and going here: 54.32.XX.XX/website2/index.html
But this gives a 404.
How do I properly access this subdirectory?
Of note, the side in website1 is what I get when I just go directly to the IP (54.32.XX.XX) which I wouldn't expect since I have another site in the "main" directory /var/www/html/
I have a Ubuntu server running Apache and have 3 sites under /var/www/website/abc, /var/www/website/xyz and /var/www/website/lmn. I have 3 domains (www.abc.com, www.xyz.com, www.lmn.com) mapped to same machine (mapped same ip to 3 different domains on godaddy).
So I googled around and found this link - virtual host setup and made abc.com.conf in /etc/apache2/sites-available/ and correspondingly for other sites. Enabled the sites and then restarted apache but same site(/var/www/website/abc) appears on all 3 domains. I rechecked the paths but they seem to be correct. I can't figure out what is wrong. How can I route them to their corresponding sites?
It would be helpful in the future if you share your code (in this case the apache config files) to figure out what's wrong. In any case, this is roughly how the files can look (they don't have to look like this, there are other ways it can be configured).
First check /etc/apache2/apache2.conf and make sure you see the following code:
IncludeOptional sites-enabled/*.conf
The apache2.conf file is the primary configuration file. That line above includes all of the configuration files in the site-enabled folder. If you use a Red Hat derived OS you'll notice that the configuration file structure is different (Debian derivatives like Ubuntu like to split everything up into tons of configuration files, Red Hat derivatives keep it together)
Make sure that each of the files in the sites-enabled folder includes lines that look like this.
For abc.com.conf:
<VirtualHost *:80>
ServerName www.abc.com
DocumentRoot /var/www/website/abc
</VirtualHost>
If you also want "abc.com" to point to this virtual host enter "ServerAlias abc.com" underneath the ServerName line. What you're doing here is creating a VirtualHost block for any ip address (*) on port 80 (:80). You could replace the * in the opening VirtualHost line with your external ip address if you want to make sure that the VirtualHost is only matched to a particular ip (this is only potentially needed if there are multiple external ips pointing to your webserver). The ServerName line tells apache to match this VirtualHost whenever the Host HTTP header is www.abc.com. ServerAlias can be used to specify additional Hosts to match. Remember that www.abc.com and abc.com are treated as different Hosts. The DocumentRoot line sets the directory from which files are served.
Similarly for xyz.com.conf:
<VirtualHost *:80>
ServerName www.xyz.com
DocumentRoot /var/www/website/xyz
</VirtualHost>
If you also want "xyz.com" to point to this virtual host enter "ServerAlias xyz.com" underneath the ServerName line.
And finally for lmn.com.conf:
<VirtualHost *:80>
ServerName www.lmn.com
DocumentRoot /var/www/website/lmn
</VirtualHost>
If you also want "lmn.com" to point to this virtual host enter "ServerAlias lmn.com" underneath the ServerName line.
I'm just learning about Apache virtual hosts. I'd like to have two virtual hosts of the form:
sitea.mydomain.org
siteb.mydomain.org
I own mydomain.org and both sitea.mydomain.org and siteb.mydomain.org of the NS points to the same IP address. I thought I could get the server to point to different webpages by making two sites in sites-available called sitea.mydomain.org and siteb.mydomain.org, but both of those entries seem to resolve to the default site.
Does this sound like a correct configuration, or even something that's possible? If so, can anyone point me in the right direction?
Having those two files, you will need to have ServerName and maybe ServerAlias-Directives in them. For example in the file sitea.mydomain.org:
<VirtualHost *:80>
ServerName sitea.mydomain.org
ServerAlias www.sitea.mydomain.org anothersitea.mydomain.org
DocumentRoot /root/directory
</VirtualHost>
Same goes for siteb. Also, create a symlink into sites-enabled.
You need to use a2ensite after creating a site in sites-available.
It does a necessary job, and put a symbolic link in sites-enabled.
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.
I've got a pretty straightforward issue with a linux based Apache 2.2 server I am setting up. I want to setup two totally different domains on the same server.
But it only serves content from the first tag! I've searched StackOverflow and read items at Apache.org but no luck.
I followed the directions on Apache.org and put these two sections at the bottom of my http.conf file.
<VirtualHost *:80>
DocumentRoot /var/www/mydomain1
ServerName sub1.mydomain1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/mydomain2
ServerName sub2.mydomain2.com
</VirtualHost>
Now when I use a browser to go to: http://sub1.mydomain1.com it comes up fine. But if I go to http://sub2.mydomain2.com I still only get the content that located in /var/www/webfiles/mydomain1.
I did many of the obvious things such as:
- service httpd restart
- I changed the order of the two entries in my httpd.conf and once again, it only serves the first one in the list.
- One support doc I had Googled said to make sure to have the following entry point to a valid domain on your system. So I entered this (but it didn't change anything):
ServerName sub2.mydomain2.com:80
It must be something silly but I can't figure it out!
Ok, I figured it out. It was pretty silly. I just needed to uncomment this line so I would actually use all the virtual hosts:
NameVirtualHost *:80
You need to set up the two domains in two separate virtual hosts. Generally when I do this I like to split off an include directory full of virtual host files, with each file containing one virtual host.
<VirtualHost *:80>
ServerName site1.com
DocumentRoot "/var/www/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.com
DocumentRoot "/var/www/site2"
</VirtualHost>