LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-26-2012, 08:27 AM   #1
kevtucker
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Rep: Reputation: 0
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
 
Old 05-26-2012, 08:57 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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
 
1 members found this post helpful.
Old 05-26-2012, 12:39 PM   #3
kevtucker
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Original Poster
Rep: Reputation: 0
Hi, Thanks for your reply but it still does not work.

It still goes to the example1 homepage.

Kevin
 
Old 05-26-2012, 01:03 PM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Originally Posted by kevtucker View Post
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
 
Old 05-26-2012, 01:26 PM   #5
kevtucker
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Original Poster
Rep: Reputation: 0
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
 
Old 05-26-2012, 04:32 PM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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
 
Old 05-26-2012, 05:19 PM   #7
kevtucker
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Original Poster
Rep: Reputation: 0
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
 
Old 05-27-2012, 09:17 AM   #8
kevtucker
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bathory View Post
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
 
Old 05-27-2012, 11:17 AM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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)
 
1 members found this post helpful.
Old 05-27-2012, 11:32 AM   #10
kevtucker
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bathory View Post
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
 
Old 05-27-2012, 11:58 AM   #11
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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
 
Old 05-27-2012, 12:10 PM   #12
kevtucker
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Original Poster
Rep: Reputation: 0
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
 
Old 05-27-2012, 12:11 PM   #13
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73
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.
 
Old 05-27-2012, 12:22 PM   #14
kevtucker
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by robertjinx View Post
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.
 
Old 05-27-2012, 12:23 PM   #15
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73
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.

Last edited by robertjinx; 05-27-2012 at 12:25 PM.
 
  


Reply

Tags
apache2, redirect, ubuntu


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache2 - having trouble setting up multiple domains under debian etch walterbyrd Linux - Software 3 01-08-2010 07:03 PM
[SOLVED] Apache2 - virtual host defaulting to default host slimjim Linux - Server 1 10-31-2009 01:47 AM
Virtual Host Redirect Issue DigiDave Linux - Software 1 10-23-2003 01:40 PM
Apache Virtual Host Redirect granny Linux - Networking 5 05-22-2003 01:20 PM
How do we direct Multiple Domains to the Same Mail host? eciit Linux - Networking 1 08-26-2002 05:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration