LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-16-2011, 03:39 PM   #1
smch1
LQ Newbie
 
Registered: Jun 2011
Posts: 5

Rep: Reputation: Disabled
RHEL 5 apache name based virtual host not working


I have setup apache webserver on RHEL5 working fine for months now. Next task is to add another domain name to the webserver using the same IP address. I have been trying to set up apache name based virtual host for the past several days without success. Each time i try elinks http://www.exampletst.com it went to the main page sales.example1.com. Main page sales.example1.com is on DNS but 2nd domain www.exampletst.com is not created on DNS yet. I just doing testing first on /etc/hosts.

10.145.13.10 sales.example1.com sales
10.145.13.10 www.exampletst.com


I have tried googling, search forum, and read documentation. I have checked my httpd.conf file several times but there must be some simple step or config error that i might miss

Apache version is 2.2.3. Output of my httpd.conf file:-

NameVirtualHost *:80

# Default Virtual Host
<VirtualHost *:80>
ServerName sales.example1.com
DocumentRoot /var/www/html
DirectoryIndex index.html index.shtml index.php
</VirtualHost>

<VirtualHost *:80>
ServerName www.exampletst.com
DocumentRoot /var/www/virtual/tours
ErrorLog /var/log/httpd/tours_error_log
CustomLog /var/log/httpd/tours_access_log common
DirectoryIndex index.html index.shtml
<Directory "/var/www/virtual/tours/">
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
 
Old 06-16-2011, 04:45 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,438

Rep: Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739
Hi,
Quote:
I just doing testing first on /etc/hosts.

10.145.13.10 sales.example1.com sales
10.145.13.10 www.exampletst.com
You should use a single line for each IP, so edit /etc/hosts and use:
Code:
10.145.13.10 sales.example1.com www.exampletst.com sales
Regards
 
Old 06-17-2011, 08:05 AM   #3
smch1
LQ Newbie
 
Registered: Jun 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Bathory,

I have tried using a single line for each IP a couple of times. I tried it once more time just now but still does not work.
 
Old 06-17-2011, 08:13 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175
You need to separate the problems.

The first step is to make sure that sales.example.com (or whatever) resolves to the IP-address that you think it does ... both here and on any other computer that will be accessing the site. From the various computers, try a command like ping sales.example.com. The IP-address should be looked-up and it should be the right one.

The next step is to look at the Apache access-logs and error-logs. Did it, in fact, see the incoming connection request, and if so, could it determine that it was a particular virtual-host? Did Apache find any errors or inconsistencies in the directives?

I normally define separate log-file directories for each virtual host definition, so that I can easily separate Apache's responses.
 
Old 06-17-2011, 08:35 AM   #5
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,438

Rep: Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739
Quote:
Originally Posted by smch1 View Post
Bathory,

I have tried using a single line for each IP a couple of times. I tried it once more time just now but still does not work.
Then have a look at /etc/nsswitch.conf and make sure you have
Code:
hosts: files dns
 
Old 06-17-2011, 09:21 AM   #6
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Hi,

my best guess would be to look at this similar problem
 
Old 06-17-2011, 10:22 AM   #7
mk27
Member
 
Registered: Sep 2008
Distribution: fedora, gentoo, ubuntu
Posts: 148

Rep: Reputation: 23
Whoops! Same point as bathory, above:

Quote:
Originally Posted by man hosts
This file is a simple text file that associates IP addresses with hostnames, one line per IP address. For each host a single line should be present with the following information:

IP_address canonical_hostname [aliases...]
Quote:
Originally Posted by smch1 View Post
I tried it once more time just now but still does not work.
You should leave it that way (on one line) though, in case you find the problem somewhere else and this screws it up, making it impossible to tell what's wrong.

Last edited by mk27; 06-17-2011 at 10:26 AM.
 
Old 06-17-2011, 02:19 PM   #8
smch1
LQ Newbie
 
Registered: Jun 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Checked /etc/nsswitch.conf
hosts: files dns

No Apache access or error messages at all for virtual host and for main host too. I don't know where else to look for clues. Nothing on /var/log/messages.

I have put the Listen directives on httpd.conf following lithos suggestion link but no luck
Listen 10.145.13.10:80
 
Old 06-17-2011, 03:46 PM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,438

Rep: Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739
Hi,

Just to eliminate the possibility it's a name resolution problem, try to ping both sales.example1.com and www.exampletst.com and see if they resolve to the same IP.

Next, to check for apache misconfiguration, use:
Quote:
Listen 80
...
NameVirtualHost *:80
...
<VirtualHost *:80>
as in your initial configuration. Run:
Code:
httpd -S
to see if you have both vhosts listed. You may swap their definitions and see if www.exampletst.com becomes the default one. Of course you need to restart apache after making changes.
Also check /var/log/httpd/tours_access_log to see if you ever access that vhost.

Regards
 
Old 07-26-2011, 08:57 AM   #10
smch1
LQ Newbie
 
Registered: Jun 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Bathory,

Ping both sales.example1.com and www.exampletst.com resolve to the same IP. Run httpd -S i could see 2 vhosts

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443 sales.example.com (/etc/httpd/conf.d/ssl.conf:81)
*:80 is a NameVirtualHost
default server sales.example.com (/etc/httpd/conf/httpd.conf:1004)
port 80 namevhost sales.example.com (/etc/httpd/conf/httpd.conf:1004)
port 80 namevhost www.exampletst.com (/etc/httpd/conf/httpd.conf:1025)
Syntax OK

I swapped www.exampletst.com to become default and it pull out the pages. No messages at all on /var/log/httpd/tours_access_log. I was wondering if i was able to access www.exampletst.com vhost at all.
 
Old 07-26-2011, 11:16 AM   #11
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,438

Rep: Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739Reputation: 1739
Huh, everything looks right in apache configuration.
Quote:
I swapped www.exampletst.com to become default and it pull out the pages. No messages at all on /var/log/httpd/tours_access_log. I was wondering if i was able to access www.exampletst.com vhost at all.
There should be log entries in /var/log/httpd/tours_access_log if you can access http://www.exampletst.com when it's the 1st (default) vhost.
Anyway, try to flush your browser's cache, or use a different browser and see if you can access both vhosts.
 
Old 07-28-2011, 09:33 AM   #12
smch1
LQ Newbie
 
Registered: Jun 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks for all the help Bathory. I was looking at the wrong httpd.conf file all the time. Now everything is working fine.
 
  


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
how to set apache virtual hosts Host-Based Security? hocheetiong Linux - Newbie 2 01-17-2014 04:20 AM
Name based virtual Host for Apache and Tomcat dinakumar12 Linux - Server 6 06-07-2011 09:12 AM
can not ping from host (RHEL 6) to RHEL 5 in (virtual)? manalisharmabe Linux - Newbie 1 05-01-2011 12:55 PM
Name and IP based virtual host in Apache hifun Linux - Newbie 5 06-17-2009 01:06 PM
Adding virtual interface for IP based virtual host pridefc Linux - General 6 03-16-2008 03:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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