LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices



Reply
 
Search this Thread
Old 04-30-2005, 04:24 AM   #1
SiLiCoN
Member
 
Registered: Sep 2004
Location: India
Distribution: Solaris 9, FreeBSD 4.10, Slackware, RedHat, Knoppix,
Posts: 84

Rep: Reputation: 15
Question Apache VirtualHost Redirect Problem...


Hi,

I have set up Apache for the LAN. Every thing is working fine...except that when an 404 error occurs for the first virtual host, apache redirects it to the home page of the first virtual host. However for other virtual hosts, it does not happen like that and works perfectly the way it shud work (giving a Not Found 404 error message).

<VirtualHost 192.168.1.21>
ServerAdmin whatever@whatever.net
DocumentRoot /home/john
ServerName TestServer
ScriptAlias /cgi-bin/ /home/john/cgi-bin/
ErrorLog logs/error.log
TransferLog logs/john.log
</VirtualHost>

<VirtualHost 192.168.1.22>
ServerAdmin whatever@whatever.net
DocumentRoot /home/johnnie
ServerName TestServer
ScriptAlias /cgi-bin/ /home/johnnie/cgi-bin/
ErrorLog logs/error.log
TransferLog logs/johnnie.log
</VirtualHost>

...
So whenever i type something like http://192.168.1.21/doesnotexist.html - it redirects me to the home page for 192.168.1.21
Also the Document Root is set to /home ( incase that helps ) and i m running 1.3.x under FreeBSD 4.10...


Thanks for the reply in Advance,
SiLiCoN
 
Old 04-30-2005, 09:11 PM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Are both these virtual hosts on the same machine where you have two IP's with two NIC's in place? If your wanting to redirect to another machine behind your firewall using only one public IP address so it redirects to the other virtual host hosted on the second machine, you have to do something like this:

Code:
<VirtualHost *:80>
    ServerName virtualname.domain.com
    RewriteEngine On
    RewriteRule     ^(.*)$     http://192.168.1.22$1 [P]
</VirtualHost>
And you can't have two virtual hosts with the same ServerName.. that's probably one reason the second one keeps going back to the first.. etc.
 
Old 04-30-2005, 09:55 PM   #3
ApachePadowan
LQ Newbie
 
Registered: Apr 2005
Location: FL
Distribution: Fedora Core 10
Posts: 25

Rep: Reputation: 15
Similar Problem

I have a similar problem.

I have setup 2 virtual hosts, looks something like this:
<VirtualHost myIP:80>
DocumentRoot /var/www/html

ServerAdmin myemail@server.com
ServerName mydomain.com

ServerAlias www.mydomain.com

DirectoryIndex index.php index.html index.htm index.shtml

<Directory "/var/www/html">
AllowOverride all
</Directory>

LogLevel debug
HostNameLookups off

</VirtualHost>

# Virtual host development
<VirtualHost myIP:80>
DocumentRoot /var/www/develop/

ServerAdmin mymail@mail.com
ServerName develop.mydomain.com

<Directory "/var/www/develop/">
AllowOverride all
</Directory>

LogLevel debug
HostNameLookups off

</VirtualHost>
___________________________

When I go to develop.mydomain.com, I get the index page of my first VHost at the /var/www/html directory, as opposed to the /var/www/develop directory.

I have only one IP, but it should make no difference how many IPs I have as long as Apache is set to look for the URL.
 
Old 05-02-2005, 01:10 AM   #4
SiLiCoN
Member
 
Registered: Sep 2004
Location: India
Distribution: Solaris 9, FreeBSD 4.10, Slackware, RedHat, Knoppix,
Posts: 84

Original Poster
Rep: Reputation: 15
hi trickykid,

Thanks for the reply...I have just one NIC (aliased from 192.168.1.21- 192.168.1.25). Virtual hosts from 192.168.1.22 - 192.168.1.25 are working fine...just that the first virtual host (which is also the actual ip of the NIC) i'e' 192.168.1.21 does not give me a NOT found (404 error) instead it redirects me to the home page of 192.168.1.21....And yes all of the 5 virtual hosts are in the same machine.

Regards,
SiLiCoN

Last edited by SiLiCoN; 05-02-2005 at 01:11 AM.
 
Old 05-02-2005, 03:08 AM   #5
SiLiCoN
Member
 
Registered: Sep 2004
Location: India
Distribution: Solaris 9, FreeBSD 4.10, Slackware, RedHat, Knoppix,
Posts: 84

Original Poster
Rep: Reputation: 15
Code:
When I go to develop.mydomain.com, I get the index page of my first VHost at the /var/www/html directory, as opposed to the /var/www/develop directory.

I have only one IP, but it should make no difference how many IPs I have as long as Apache is set to look for the URL.
Hi ApachePadowan,

Is the DNS working fine, try doing a dig or nslookup on www.mydomain.com and develop.mydomain.com and see if they point to the place u r trying to point. (which i guess is working fine otherwise it would have given a not found message).
Since its a NameVirtual host, put a NameVirtualHost <YOUR_IP> statement just before the two virtual host statement and i guess things will work out fine.
What i mean is - your virtual host declaration should be

NameVirtualHost YOUR_IP

<VirtualHost YOUR_IP>
...
</VirtualHost>

<VirtualHost YOUR_IP>
...
</VirtualHost>


Regards,
SiLiCoN
 
Old 05-03-2005, 09:41 AM   #6
ApachePadowan
LQ Newbie
 
Registered: Apr 2005
Location: FL
Distribution: Fedora Core 10
Posts: 25

Rep: Reputation: 15
Thanks, SiLiCon... What I actually did to get it to work was as simple as replacing my IP with a *... Working just fine now...
 
  


Reply


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
Apache 2 VirtualHost woes, permissions problem, just can't work it out. utow Linux - Software 2 04-19-2005 02:48 PM
Apache - Problem when configure VirtualHost b:z Linux - Networking 17 04-07-2005 03:44 AM
Apache URL redirect problem kdogksu Linux - Networking 2 03-26-2005 03:22 PM
VirtualHost Apache 2 Problem Chris_K1 Linux - Networking 0 01-25-2005 11:00 AM
Apache: Virtualhost configuration problem deepika Linux - Software 3 08-12-2003 11:13 AM


All times are GMT -5. The time now is 01:34 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration