LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-14-2012, 03:19 PM   #1
linuxreza
Member
 
Registered: Jan 2012
Location: Mumbai, India
Distribution: Redhat
Posts: 30
Blog Entries: 1

Rep: Reputation: Disabled
Apache vitual host issue


Hello Friends .
i have install apache in my RHEL5.6 .
# yum install httpd
After installing Apache i run the httpd service by.
# yum restart httpd
than i check the default page in Firefox and elinks it worked properly.
than i put a simple website index.html in the default document root /var/www/html/. restart the httpd service and it worked fine in the bowsers.

i tried to configure a name based virtualhost here is the configuration .
Code:

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier 
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>
<VirtualHost sports.com:80>
    ServerAdmin admin@sports.com
    DocumentRoot /var/www/vhosts/sports.com/html/
    ServerName sports.com
    ErrorLog /var/www/vhosts/sports.com/log/error_log
    CustomLog /var/www/vhosts/sports.com/log/access_log common
</VirtualHost>
I put another index.html file in the /var/www/vhosts/sports.com/html/ directory.

After making this configuration i restarted the httpd service again.
Now the problem is here.

Now when i test these configuration in the browser , I typed localhost in the browser now the index.html of the localhost machine is not showing now. The index.html page of sports.com is coming instead of localhost's index.com .

## I have added the sports.com in the /etc/hosts/ file in the line of 127.0.0.1 after localhost
127.0.0.1 localhost localhost.localdomain sports.com
####


Now where is the problem ... Kindly help me in this.

Thanks and regards
Md Reza

Last edited by linuxreza; 06-15-2012 at 01:46 AM.
 
Old 06-14-2012, 03:51 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Your problem is right in your post. Review the NameVirtualHost directive. This will map the virtual host you follow it with to the IP address you specify. So your *:80 NameVirtualhost line is going to serve the next virtualhost(your sports.com vhost) as the one for all the IPs on the system, including localhost. Remove that line and it will not serve the sports.com content on the localhost host name or any of the IPs directly.
 
Old 06-14-2012, 06:04 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Code:
# this doesn't look right to me
yum restart httpd

# should be 
service httpd restart
yum is for installing/updating/removing pkgs.
 
Old 06-15-2012, 01:49 AM   #4
linuxreza
Member
 
Registered: Jan 2012
Location: Mumbai, India
Distribution: Redhat
Posts: 30

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Now i posted the new configuration code .. still getting the same error...

Kindly help me.
 
Old 06-15-2012, 02:06 AM   #5
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

Rep: Reputation: 42
the document root in your httpd.conf should be :/var/www/vhosts/sports.com/html/ since this is where you put the index.html
 
Old 06-15-2012, 02:19 AM   #6
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 525

Rep: Reputation: 95
Hi,

After configuring any virtual host, Apache only honor virtual hosts in order they appear in the configuration files.
So in order to still avail your default web page, you need to also define an additional virtual host for it.
Something as:
Code:
<VirtualHost *:80>
    ServerAdmin root@localhost
    DocumentRoot /var/www/html/
    ServerName localhost.localdomain
</VirtualHost>
 
Old 06-15-2012, 02:42 AM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by tshikose View Post
Hi,

After configuring any virtual host, Apache only honor virtual hosts in order they appear in the configuration files.
So in order to still avail your default web page, you need to also define an additional virtual host for it.
Something as:
Code:
<VirtualHost *:80>
    ServerAdmin root@localhost
    DocumentRoot /var/www/html/
    ServerName localhost.localdomain
</VirtualHost>
To clarify this, Apache will serve the FIRST virtual host if there is no match, so put that default example ABOVE any others you create.
 
Old 06-16-2012, 09:31 AM   #8
linuxreza
Member
 
Registered: Jan 2012
Location: Mumbai, India
Distribution: Redhat
Posts: 30

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Thanks you very much for making me understand about this concept.
 
  


Reply



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 Virtual Host issue ciphyre Linux - Server 3 10-24-2008 11:29 AM
Apache: virtual host issue Zeno McDohl Linux - Server 17 12-21-2006 02:59 PM
Virtual Host issue with apache gauge73 Linux - Networking 1 07-12-2005 02:00 PM
Apache Virtual Host problem - DNS or DHCP issue? costrevs Linux - Software 16 03-23-2005 07:50 AM
[HELP] Apache server running in vitual pc to_vijayarun Linux - Software 9 11-21-2003 01:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:31 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