Solved

Can I get a sample of httpd.conf for Apache web servers on Red Hat Pro 9.0, using Name-Based Virtual Hosts?

Posted on 2004-08-25
8
1,150 Views
Last Modified: 2013-12-16
Hi,

I tried to set up web server Apache on a Red Hat Linux Pro 9.0 with virtual hosts, using name-based virtual hosts.

If I removed all the virtual hosts directives, the web server works correctly as expected, i.e. no virtual hosts at all. The web server serves only 1 domain name and the index.html file is placed in the default DocumentRoot directory "/var/www/html"

If I added the virtual host directives into the httpd.conf, even only 1 virtual host (to test it), the web server starts with error and then it can only gets into the test page and couldn't get to the virtual host DocumentRoot directory.

I've tried to solve this problme for 2 weeks and I couldn't make it work correctly. I thought I would be very helpful for me if I can learn from a working httpd.conf file. If any of you have a httpd.conf file that contains virtual host directives, using name-based virtual hosts, and is currently working correctly, please give me a copy ot it. Of course, you need to replace all the specific details of your web site like IP address, etc. with the generic info. Any help would be appreciated

Thanks a lot for any help,

Rfr1tz

0
Comment
Question by:rfr1tz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 38

Expert Comment

by:yuzh
ID: 11898791
1. Make use you have DNS record for all Virtuhosts. (If you have only one NIC, the VirtualHost
      can use the same IP)
      You can defined a A Record for your mainhosts, and make all the other VirtualHost as the
      CName of the mainhosts.
 2. Have a look at the following VirtualHost setup examples:
      http://www.experts-exchange.com/Web/Web_Servers/Apache/Q_20859488.html
      When you start to edit the httpd.conf file, start with a simple VirtualHost file as
      in the example, once you get it working, add on more customized items for each website.

   3. Check all the dir path, you make sure they are correct in the httpd.conf, start apache and test it.

   also please have a look at the following httpd.conf example file:
   http://www.pantz.org/webservers/apache/httpdexample.shtml
   
   5. Modify the httpd.conf for each VirtualHost (customized items), please do one at a time.

0
 
LVL 16

Expert Comment

by:xDamox
ID: 11906541
<VirtualHost www.example.com>
    ServerAdmin webmaster@host.some_domain.com
    DocumentRoot /www/docs/host.some_domain.com
    ServerName host.some_domain.com
    ErrorLog logs/host.some_domain.com-error.log
    CustomLog logs/host.some_domain.com-access.log common
</VirtualHost>
0
 
LVL 3

Author Comment

by:rfr1tz
ID: 11907695
Hi,

I followed the solutions to other questions and set up my httpd.conf as follows:

//--------------------

ServerName www.xyz.com

UseCanonicalName on

DocumentRoot "/var/www/html"


# Virtual host Default Virtual Host
<VirtualHost _default_>      
       ServerName _default_
       ServerSignature email
      DirectoryIndex  index.php index.html index.htm index.shtml
       ServerSignature email
       LogLevel  warn
       HostNameLookups off
</VirtualHost>


#
# Use name-based virtual hosting.
#
NameVirtualHost 192.168.1.100

# Virtual host: opensources.biz
<VirtualHost 192.168.1.100>       
        ServerName www.xyz.com
      ServerAlias *.xyz.com
      DocumentRoot /var/www/xyz
          <Directory /var/www/xyz>
                Options            Indexes Includes FollowSymLinks
                AllowOverride      None
                Order            allow,deny
                 Allow            from all
           </Directory>
           DirectoryIndex      index.html index.php index.htm default.php default.htm default.html
       ServerAdmin       "email address"
       ServerSignature email
</VirtualHost>


# Virtual host: ex-utexas.homelinux.com
<VirtualHost 192.168.1.100>       
        ServerName www.ex-utexas.homelinux.com
      ServerAlias *.ex-utexas.homelinux.com
      DocumentRoot /var/www/exutexas
          <Directory /var/www/exutexas>
                Options            Indexes Includes FollowSymLinks
                AllowOverride      None
                Order            allow,deny
                 Allow            from all
           </Directory>
      ServerAdmin       "email address"
       ServerSignature email
</VirtualHost>

//--------------------------

I can only access the first Virtual Host, i.e. www.xyz.com. Other virtual hosts only point to the default test page of the server.

Do you have any idea about this?

Thanks a lot,

Rfr1tz

0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 38

Expert Comment

by:yuzh
ID: 11909764
Hi Rfr1tz,

    Have you defined your main host as a Virtualhost?
    You need to defines your mainhost as a Virtualhost before the other VirtualHost.

   
0
 
LVL 3

Author Comment

by:rfr1tz
ID: 11916782
Hi yuzh,

"Have you defined your main host as a Virtual Host?"

Yes, I did. My main host is www.xyz.com. I set this in thhis line of the httpd.conf

ServerName www.xyz.com

To be in more details, I also define the main host as follows:

//--------------------
# Have 2 NIC cards, eth0 == 192.168.1.100; all virtual hosts are defined on this NIC
Listen 192.168.1.100:80
Listen 192.168.1.101:80

# ... other directives

### Section 2: 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#
#
User apache
Group apache

ServerAdmin root@localhost
ServerName www.xyz.com
UseCanonicalName on
DocumentRoot "/var/www/html"

I also define the main host "www.xyz.com" as the first virtual host, as I posted in my previous comment.

In your comment, you mentioned "Make sure you have DNS record for all Virtual hosts.", it means that I must make my web server become a DNS server?

Right now, with current setup, I can access www.xyz.com but I couldn't access www.ex-utexas.homelinux.com. When I tried to access www.ex-utexas.homelinux.com, the only thing I can get is the default test page of the server.

I got the domain name: www.ex-utexas.homelinux.com from dyndns.org and they already added this into their DNS server. From what I understood, they map this domain name to the external IP address of my cable router in their DNS server. I already got the IP address of their DNS servers.

So do I have to set up the DNS server on my web server to map all the virtual hosts to their private IP address. i.e. 192.168.1.100?

Thanks a lot for your help,

Rfr1tz
0
 
LVL 38

Accepted Solution

by:
yuzh earned 500 total points
ID: 11928378
Hi Rfr1tz,

     Your problem is a DNS problem, I did a test for your (nslook up):

     Name:    ex-utexas.homelinux.com
    Address:  67.172.223.244
    Aliases:  www.ex-utexas.homelinux.com

    Name:    ex-utexas.homelinux.com
   Address:  67.172.223.244
   Aliases:  www.ex-utexas.homelinux.com

   the real IP of www.ex-utexas.homelinux.com is 67.172.223.244, and you are in
a private network, you need to setup your router/firewall to forward the http traffic
to 192.168.1.100 (or change your Linux box to use 67.172.223.244 as its ip address).

   To test your VirutalHost, you can defind all your virtualhost in your /etc/hosts file
  eg:

192.168.1.100  www.xyz.com
192.168.1.100 www.ex-utexas.homelinux.com

and make sure your /etc/nsswitch.conf have the hosts record looks like:

hosts:     files dns

the test to access www.ex-utexas.homelinux.com from your webserver (not other PCs).

You don't have to run your own DNS server if your ISP take care of it for you, but you do
need to sort out how to route the web traffic to your web server, it is easier for you just
use the public IP (67.172.223.244) for your Linux webserver.



     
   
0
 
LVL 3

Author Comment

by:rfr1tz
ID: 11928751
Thank you so much for your help.
Finally, it works perfectly.

Thank so much again.

Rfr1tz

0
 
LVL 38

Expert Comment

by:yuzh
ID: 11928779
You are welcome, cheers!

yuzh
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is an update and follow-up of my previous article:   Storage 101: common concepts in the IT enterprise storage This time, I expand on more frequently used storage concepts.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question