Multiple Apache2 vhosts are pointing to the same website - apache

I'm running Apache2 on Ubuntu 10, and I have my site configuration files laid out numerically and in order. My default server is psychedeli.ca, but I also run another site off the same box at mahoganytales.com. Currently, both of these domains point to the same site (the one for psychedeli.ca). The declaration NameVirtualHost *:80 is in my ports.conf file, so I'm pretty sure my global server config checks out. How can I fix this?
Here are my vhost files:
001-psycho
<VirtualHost *:80>
DocumentRoot /var/apps/psycho/public
ServerName psychedeli.ca
</VirtualHost>
002-mahogany
<VirtualHost *:80>
DocumentRoot /var/apps/mahogany/public
ServerName mahoganytales.com
</VirtualHost>

try create new conf file at /etc/apache2/conf.d, e.g., vhosts.conf
with this content in it:
NameVirtualHost *

It looks like the default configuration is in effect rather than your host entries. Following is the procedure that works in Ubuntu Apache2.
First,
create a VirtualHost in /etc/apache2/sites-available/somesite,
then a2ensite somesite to make it live.
Finally, /etc/init.d/apache2 restart to restart apache.
If you think, you have followed the above steps, then can you please confirm, that you have your hosts files in /etc/apache2/sites-enabled/?

Each domain name needs to have it's own single unique ip address, that's how different sites are found.
By using the *:80 in the virtual host directive, you're instructing Apache to listen on all IP addresses, port 80 and send it to this directory. With your second vhost, you're doing the same thing (All IP's port 80, and send it there). Well, since you're giving it two conflicting statements, it takes the first match, and uses it.
If you want to serve multiple websites, each must answer to it's own unique IP address, ie:
site aaa.com - 145.25.82.110
site bbb.com - 145.25.82.111
From there, each vhost entry will listen on it's own ip address and port for each site. In the OP's case the vhost needs to change to (using the example IPs):
&ltVirtualHost 145.25.82.110:80>
DocumentRoot /var/apps/psycho/public
ServerName psychedeli.ca
&lt/VirtualHost>
&ltVirtualHost 145.25.82.111:80>
DocumentRoot /var/apps/mahogany/public
ServerName mahoganytales.com
&lt/VirtualHost>
This instructs the server to listen on static IP 1 port 80 (as defined in the named.conf and associtated bind config files, and send it to the first site base directory, and any calls on the second static IP port 80 and send it to the second site base directory.
As for configuring bind/named, that's beyond the scope of this question...

Related

Managing multiple sites on XAMPP

I have multiple sites deployed on xampp. For now, all of the sites are using one port i.e. 80. For this reason, whenever I am logged into one of the sites, I am automatically logged out from the other and vice versa. I have looked at this article to How to run multiple websites on XAMPP on Windows. And tried to follow it but I am unable to do the needful.
I have added one more port to listen
Listen 80
Listen 8080
In my httpd-vhosts.conf I have done the following
NameVirtualHost *:8080
<VirtualHost *:8000>
DocumentRoot "F:\xampp\htdocs\mdc"
ServerName localhost:8080
<\VirtualHost>
After doing this I have turned off my xampp and then tried to restart apache and mysql. But apache is not starting
My URL is http://localhost:8080/mdc/backend/web
Note: Without doing any virtual host setting the above URL is accessible on both 80 and 8080 ports
Update 1
Herer is my httpd.conf file
This is not a fix for your issue, Here i will explain how i manage multiple websites on xampp.
First i assumes that your using windows
i always use the same port with different server names.
on : E:\xampp\apache\conf\extra\httpd-vhosts.conf (In my case i installed xampp on E drive)
i added this code
<VirtualHost *:80>
DocumentRoot "e:/xampp/htdocs/mysite1"
ServerName mysite1.flames.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "e:/xampp/htdocs/mysite2"
ServerName mysite2.flames-team.com
</VirtualHost>
And on ( C:\Windows\System32\drivers\etc\hosts) my windows host file i added this lines
127.0.0.1 mysite1.flames.com
127.0.0.1 mysite2.flames-team.com
With this approach you can access the site with a clean readable URLs
In this case if you want to see the first site just enter this URL mysite1.flames.com on browser.
Cheers
Write the closing tag </VirtualHost> instead of <\VirtualHost> in the file httpd-vhosts.conf. I did it and it worked for me.

Running multiple domains on same server

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.

Apache different sites on different ports, still links to same site. Bind9 for domain names

I've been trying to create 3 different domains linking to 3 different sites on the same machine, 2 which works but the third on the different port links to the first page.
My apache config looks like this:
Listen 81
NameVirtualHost *:81
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/www
</VirtualHost>
<VirtualHost *:80>
ServerName www2.example.com
DocumentRoot /var/www/www2
</VirtualHost>
<VirtualHost *:81>
ServerName controlpanel.example.com
DocumentRoot /var/www/controlpanel
</VirtualHost>
I've used Bind9 to set up the domains.
www IN A 123.123.123.123
www2 IN A 123.123.123.123
controlpanel IN A 123.123.123.123
www and www2 works fine and shows the correct site, however controlpanel.example.com also links to the first www site. When I enter the port manualy on the ip, xxx.xxx.xxx.xxx:81, i get linked correctly. The thing is that I don't really know where I'm doing it wrong, this is the first time I'm trying anything like this. You got any ideas?
Im also running this on an old ubuntu 12.04 server.
Regarding where you're going in the comments for the previous answer:
You could add a port 80 virtualhost for controlpanel.example.com and put a single statement inside,
Redirect / http://controlpanel.example.com:81
The purpose of the ServerName is not to inform the browser what port your webserver is using. It's used for name-based virtualhosts and as a last resort for self-referential links (out of the box, self-referential links are generated with whatever the client already thought it was accessing via the Host: header)
But there is definitely something quite bizarre about your requirement. Usually the motivation is to not use custom ports, and if they are, to address the server with a low port and have the por remapped by some intermediary (load balancer, proxy).
If you want your third virtualhost to be simulataneously the defautl on port 81 and a name-based option on port 80:
Change
<VirtualHost *:81>
to
<VirtualHost *:80 *:81>
Apache finds the set of virtual hosts with the best IP:PORT based match first, then if NameVirtualHost also matches, starts looking at the ServerNames from that set.

configuration of domainname in httpd.conf and /etc/hosts

I am facing an issue with configuring domain name in my httpd.conf file. Entry in httpd.conf file.
Listen sample.com:443
<VirtualHost sample.com:443>
SSLEnable
ServerName MyIHSInstalledServerName
</VirtualHost>
KeyFile /serverPath/keyfile.kdb
SSLDisable
SSLTrace
Now I am confused on what should be the entry made in /etc/hosts
{IP} sample.com sample. Here what is the IP I should mention and is my entry in httpd.conf file correct? Please help.
Your /etc/hosts file is not really relevant to your Apache config.
For SSL virtual hosts, use either the actual ip address that you want your SSL httpd daemon to be bound to
eg
<VirtualHost 10.1.1.1:443>
or use:
<VirtualHost _default_:443>
which will bind the daemon to the first ip address not in use by any other SSL virtual host, which should work in the vast majority of cases
The name of the service is only relevant to the ServerName directive. If you include that, the httpd daemon will only respond to requests that include that name in the header.

IP based VirtualHost and Apache

I have this webserver that have an IP address xxx.xxx.xx.x, I also have a website I want to publish, but I do not have any domain for my website yet.
So in my httpd-vhosts.conf file I have this setting:
<VirtualHost xxx.xxx.xx.x>
ServerName xxx.xxx.xx.x
DocumentRoot "C:\Sites\mysite"
</VirtualHost>
And since I dont have a domain I really want to use the IP address to reach my site, but I have tried this and it does not work. I guess you HAVE to set a server name in ServerName as the title says.
Are there any ways for me to make my website public through my IP address, if yes how can I do this?
Try
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:\Sites\mysite
ServerName xx.xx.xx.xx
</VirtualHost>
Remember to restart apache,
You may also need to add,
Listen xx.xx.xx.xx:80
If you only have the one website on this server, you don't need a virtual host. Just set the DocumentRoot correctly and away you go. Also make sure Apache is listening on all IP addresses (Listen 0.0.0.0:80.)
If that doesn't work for you, from your command prompt do:
telnet xx.xx.xx.xx 80
GET /
and see what you get back - you should get your website's default page.
This is not a programming question.
But anyway,
Set the VirtualHost to * rather than a specific IP address. I don't think you need the servername either then.