LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache2 - Virtual Host redirect problem with multiple domains (http://www.linuxquestions.org/questions/linux-server-73/apache2-virtual-host-redirect-problem-with-multiple-domains-946971/)

kevtucker 05-26-2012 08:27 AM

Apache2 - Virtual Host redirect problem with multiple domains
 
Hi, looking for a bit of help with Apache2 on Ubuntu Desktop.

I have 2 names : example1.com and example2.com but having problems with redirecting.

If I type www.example1.com I get my homepage for Example 1
If I type example1.com I get Example 1 homepage again
If I type www.example2.com I get my homepage for Example 2

now the problem here is If I type example2.com it takes me to Example 1 homepage.

I have this in /etc/apache2/apache2.conf at the very bottom :

# Include the virtual host configurations:

Include sites-enabled/

<VirtualHost *:80>
DocumentRoot /Websites/example1
ServerName example1.com
<Directory "/Websites/example1">
allow from all
Options +Indexes
</Directory>
ServerAlias *.example1.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /Websites/example2
ServerName example2.com
<Directory "/Websites/example2">
allow from all
Options +Indexes
</Directory>
ServerAlias *.example2.com
</VirtualHost>



Does any one have a solution for me on this. I've tried many things but still not working correctly.

I have my DNS set up on Fasthosts for each domain in A records (www) pointing to my ip address for each domain.

Thank you for any help.

Kevin

bathory 05-26-2012 08:57 AM

Hi,

You need:
Code:

ServerAlias *.example2.com example2.com
BTW the same goes for example1.com, but this one is working because example1.com is also the default vhost

Regards

kevtucker 05-26-2012 12:39 PM

Hi, Thanks for your reply but it still does not work.

It still goes to the example1 homepage.

Kevin

bathory 05-26-2012 01:03 PM

Quote:

Originally Posted by kevtucker (Post 4688253)
Hi, Thanks for your reply but it still does not work.

It still goes to the example1 homepage.

Kevin

I guess you've restarted apache.
Then you need to clear your browser cache (or use another browser) to do your tests.

Regards

kevtucker 05-26-2012 01:26 PM

Hi,

Yes I did sudo /etc/init.d/apache2 reload and sudo /etc/init.d/apache2 restart

Still no go.

I've tried many different ways from google search but always ends up been the same.

Kevin

bathory 05-26-2012 04:32 PM

I'm not familiar with the apache installation in ubuntu, but I think you use apache2 instead of httpd. If that's the case, run
Code:

apache2 -S
to see you current configured vhosts.

May I ask why don't you use the default ubuntu way to define vhosts? Meaning you have to use /etc/apache2/sites-enabled/blah to configure and a2ensite to enable vhosts

kevtucker 05-26-2012 05:19 PM

Hi, thanks for your replies.

I set the two servers up using webmin and it set the apache2.conf like that.

I have now used your suggestion to use /sites-enabled/000-default

But still have the same problem.

I am using the server from a Virtual machine on my iMac.

I changed my host file on mac to 192.168.1.100 for www.example.com/example.com www.example1.com/example1.com and obviously that works fine for redirecting its just if I try the addresses on my macbook using a different wifi connection not connected to my network in anyway I get the redirect problem.

Thanks for your help.

Kevin

kevtucker 05-27-2012 09:17 AM

Quote:

Originally Posted by bathory (Post 4688397)
I'm not familiar with the apache installation in ubuntu, but I think you use apache2 instead of httpd. If that's the case, run
Code:

apache2 -S
to see you current configured vhosts.

May I ask why don't you use the default ubuntu way to define vhosts? Meaning you have to use /etc/apache2/sites-enabled/blah to configure and a2ensite to enable vhosts

Doing apache2 -S show the following


VirtualHost configuration:
192.168.1.103:80 is a NameVirtualHost
default server melvincloud.com (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost melvincloud.com (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost photo-revive.com (/etc/apache2/sites-enabled/000-default:12)
Syntax OK

bathory 05-27-2012 11:17 AM

Quote:

VirtualHost configuration:
192.168.1.103:80 is a NameVirtualHost
default server melvincloud.com (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost melvincloud.com (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost photo-revive.com (/etc/apache2/sites-enabled/000-default:12)
Syntax OK
Check your dns.
From here both domains above resolve to the same IP (88.208.x.x), while both subdomains with the www prefix resolve to a different IP (94.168.x.x)

kevtucker 05-27-2012 11:32 AM

Quote:

Originally Posted by bathory (Post 4688811)
Check your dns.
From here both domains above resolve to the same IP (88.208.x.x), while both subdomains with the www prefix resolve to a different IP (94.168.x.x)

In my Fasthosts control panel for DNS on each domain it shows the following :

exchange 213.171.192.xxx

mail 213.171.216.xxx

mailserver 213.171.216.xxx

mcp 213.171.195.xxx

smtp 213.171.216.xxx

webmail 213.171.216.xxx

88.208.xxx.xxx

www 94.168.xxx.xxx

I have web forwarding set-up as http://94.168.250.xxx

Is this correct or do I need to remove the 88.208.xxx.xxx which has no prefix on it ?

Sorry for been a pain. Benn trying for days to resolve this.

Kevin

bathory 05-27-2012 11:58 AM

Quote:

88.208.xxx.xxx

www 94.168.xxx.xxx

I have web forwarding set-up as http://94.168.250.xxx

Is this correct or do I need to remove the 88.208.xxx.xxx which has no prefix on it ?
Why don't you make both domain1.com and www.domain1.com resolve to the same IP? And do the same for domain2.com and www.domain2.com

kevtucker 05-27-2012 12:10 PM

Hi,

I have changed

88.208.xxx.xxx

www 94.168.xxx.xxx

to :

94.168.xxx.xxx

www 94.168.xxx.xxx

on both of the DNS settings page on Fasthosts control panel but getting same.

Think i'm going to give up on it now. I'm going round in circles trying to fix it. :)

Even if I switch the VirtualHost in /etc/apache2/sites-available/default file so example2.com is the first entry it all reverses with same problem.

Thanks.

Kevin

robertjinx 05-27-2012 12:11 PM

You need to define the default "website" as a vhost also. I'm talking about the setup in apache httpd.conf where you have ServerName and so on. You have 2 vhosts and the default setup so you need to have 3 vhosts.

kevtucker 05-27-2012 12:22 PM

Quote:

Originally Posted by robertjinx (Post 4688855)
You need to define the default "website" as a vhost also. I'm talking about the setup in apache httpd.conf where you have ServerName and so on. You have 2 vhosts and the default setup so you need to have 3 vhosts.

I only have

ServerName localhost

in my httpd.conf file.

How would I go about doing this if you dont mind.

robertjinx 05-27-2012 12:23 PM

Create a vhost with localhost and DocumentRoot as it's set by default in the httpd.conf

You dont need ServerAlias for this.

Code:

<VirtualHost *:80>
 DocumentRoot [where the documentroot is set in httpd.conf]
 ServerName localhost
</VirtualHost>

and thats it.


All times are GMT -5. The time now is 04:16 AM.