LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Apache vitual host issue (https://www.linuxquestions.org/questions/linux-newbie-8/apache-vitual-host-issue-4175411490/)

linuxreza 06-14-2012 03:19 PM

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

Kustom42 06-14-2012 03:51 PM

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.

chrism01 06-14-2012 06:04 PM

Code:

# this doesn't look right to me
yum restart httpd

# should be
service httpd restart

yum is for installing/updating/removing pkgs.

linuxreza 06-15-2012 01:49 AM

Now i posted the new configuration code .. still getting the same error...

Kindly help me.

cbtshare 06-15-2012 02:06 AM

the document root in your httpd.conf should be :/var/www/vhosts/sports.com/html/ since this is where you put the index.html

tshikose 06-15-2012 02:19 AM

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>


acid_kewpie 06-15-2012 02:42 AM

Quote:

Originally Posted by tshikose (Post 4703795)
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.

linuxreza 06-16-2012 09:31 AM

Thanks you very much for making me understand about this concept.


All times are GMT -5. The time now is 06:08 AM.