LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache2 - Virtual Host redirect problem with multiple domains (https://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.

bathory 05-27-2012 12:26 PM

Now everything resolves correctly. You can flush your dns to check, or you can wait until dns changes are propagated
You also need to clear your browser cache.

@robertjinx
There is no need for a default "website". It's the first vhost defined in sites-available/default. See the output of "apache2 -S"

kevtucker 05-27-2012 12:45 PM

Quote:

Originally Posted by robertjinx (Post 4688862)
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.

Doing that throws up all this after /etc/init.d/apache2 restart

[Sun May 27 16:51:27 2012] [error] VirtualHost localhost:80 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results
[Sun May 27 16:51:27 2012] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Sun May 27 16:51:27 2012] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Sun May 27 16:51:27 2012] [warn] NameVirtualHost 192.168.1.103:80 has no VirtualHosts
... waiting [Sun May 27 16:51:28 2012] [error] VirtualHost localhost:80 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results
[Sun May 27 16:51:28 2012] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Sun May 27 16:51:28 2012] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Sun May 27 16:51:28 2012] [warn] NameVirtualHost 192.168.1.103:80 has no VirtualHosts
[ OK ]

I've changed it back to how it was before without the additional host

Bathory : Did I change my DNS on Fasthosts correctly then ? Its still the same after Restart and Browser cache clear. I should wait a few hours for the DNS to propagate you recon ?

Thanks for help

Kevin

robertjinx 05-27-2012 12:49 PM

Strange, but ok.

kevtucker 05-27-2012 12:58 PM

We can now put this to SOLVED !!!!

Suddenly it's working

now when i goto example2.com it goes straight to www.example2.com

Thing it may have been to do with the DNS Records on Fasthosts.co.uk server having the additional ip address with no www prefix on it.

Thank you bathory for all your help and robertjinx for your suggestion.

kevtucker 05-27-2012 03:45 PM

Quote:

Originally Posted by kevtucker (Post 4688887)
We can now put this to SOLVED !!!!

Suddenly it's working

now when i goto example2.com it goes straight to www.example2.com

Thing it may have been to do with the DNS Records on Fasthosts.co.uk server having the additional ip address with no www prefix on it.

Thank you bathory for all your help and robertjinx for your suggestion.

It is fully working now as I have just successfully transfered both websites to a new Ubuntu Server from Ubuntu desktop and managed to move both Wordpress databases too and all working perfectly.

Thanks again.


All times are GMT -5. The time now is 04:42 PM.