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,145 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
  • 4
  • 3
8 Comments
 
LVL 38

Expert Comment

by:yuzh
Comment Utility
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
Comment Utility
<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
Comment Utility
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
 
LVL 38

Expert Comment

by:yuzh
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 3

Author Comment

by:rfr1tz
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you so much for your help.
Finally, it works perfectly.

Thank so much again.

Rfr1tz

0
 
LVL 38

Expert Comment

by:yuzh
Comment Utility
You are welcome, cheers!

yuzh
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

VM backups can be lost due to a number of reasons: accidental backup deletion, backup file corruption, disk failure, lost or stolen hardware, malicious attack, or due to some other undesired and unpredicted event. Thus, having more than one copy of …
How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now