your baddie teddie since 1983.

Configuring Virtual Hosting using Apache2 on SLES 10

Originally from: http://www.novell.com/coolsolutions/feature/19856.html

In this guide I tried to explain how to implement Virtual Hosting using Apache2 on SUSE Linux Enterprise Server 10. This guide is ESPECIALLY written for those WEB-ADMINS who are used to configuring Virtual Hosting on Redhat Enterprise Linux(RHEL 3/4). Since on a rhel Server, apache is configured using a single file i.e /etc/httpd/httpd.conf, i.e all of the virtual hosting configurations goes in /etc/httpd/httpd.conf ONLY, while in SUSE Linux Enterprise 10, we don’t edit the httpd.conf for virtual hosting.

What is Virtual Hosting:

Virtual Hosting is the art/method to run multiple websites on a single machine.

Benefits Of Virtual Hosting:

There are millions of websites on the Internet. Without Virtual Hosting it is impossible to run millions of website, because each website requires a dedicated Machine, IP and/or Port as an address to be accessed from across the world/Internet.

Types Of Virtual Hosting:

There are three types of virtual hosting.

  1. IP Based Virtual Hosting (not commonly used)
  2. Port Based Virtual Hosting (not commonly used)
  3. Name Based Virtual Hosting (commonly used)

a. IP Based Virtual Hosting:

    IP based virtual Hosting is the method to run multiple websites on a single machine, but each website must be configured to run on a different/unique IP. To configure the IP base virtual hosting we have to assign multiple IPs to the machine(server).

    Say we have a “Dell Precision 650” machine, to host 3 different websites we must assign 3 unique IP addresses to the machine, and then configure each website to listen on a dedicated IP.

    Advantage:

    Just a single physical machine will host multiple websites, otherwise we need a separate machine to host each website.

    Disadvantage:

    Requires a dedicated IP for each website.

b. Port Based Virtual Hosting:

    • To access the www.test.com, in the url user/surfer has to type the port too, as www.test.com:81
    • To access the www.wxyz.com, in the url user/surfer has to type the port too, as www.wxyz.com:82
    • To access the www.ijkl.com, in the url user/surfer has to type the port too, as www.test.com:83
  • Port base virtual Hosting is the method to run multiple websites on a single machine and even on a single/same IP, but each website must be configured to run on a different/unique Port.

    Say we have a “Dell Precision 650” machine, to host 3 different websites we just need a single dedicated/unique IP-add.

    e.g we have to host www.test.com, www.wxyz.com, and www.ijkl.comon a single machine using single/same IP-addr… we will configure www.test.comto listen on port 81, www.wxyz.comto listen on port 82, and www.ijkl.comto listen on port 83.

    Advantage:

    Just a single physical machine and IP will host multiple websites. No need to purchase multiple machines and IP-add to host multiple websites.

    Disadvantages:

    – It is quite impossible to inform the users/surfers that on which particular port the website is hosted.
    – And user/surfer must has to type the particular port in the url e.g

c. Name Based Virtual Hosting:

    To run multiple websites on a single machine and even on a single/same IP and port, we have to configure the Name-Based Virtual Hosting.

    Advantage:

    A single machine, single IP, and the default http port(80) is used to host several websites.

    Disadvantage:

    Proper DNS configuration will be required to host and access the websites hosted via Name Base Virtual Hosting.

    Note: Since other types of Virtual Hosting(IP and Port base) are not commonly used, thats why we just discuss the Name-Based virtual hosting and used the term “Virtual Hosting” for Name-Based Virtual Hosting.

Step-By-Step Configuration

Configuring Virtual-Hosting using apache2 on SLES 10

  1. First create the Directories and html files for the two websites we host using Virtual Hosting.say e.g
    a1, mkdir /srv/www/example1
    b1, echo "This is the EXAMPLE 1 website" >/srv/www/example1/index.html
    
    a2, mkdir /srv/www/example2
    b2, echo "This is the EXAMPLE 2 website" >/srv/www/example2/index.html
    ********

    After creating directories and html files for the two websites, Now we configure the apache2 to host/run the two websites using virtual hosting.

  2. in /etc/apache2/listen.conf append the following line:
    NameVirtualHost IP_OF_Server:PORT
    i.e
    
    NameVirtualHost 192.168.0.101:80
  3. then change the directory ascd /etc/apache2/vhosts.d

    cp vhost.template example1.conf
    cp vhost.template example2.conf

    NOTE: the virtual host configuration files(in our case example1.conf, and example2.conf) MUST have “.conf” in the end of their names.

  4. Have to change some required parameters as per the environment
    1. Minimal Required Configuration for example1 Websitein /etc/apache2/vhosts.d/example1.conf
      <VirtualHost 192.168.0.101:80> *
      
         ServerName www.example1.org
         DocumentRoot /srv/www/example1
      
         <Directory "/srv/www/example1"> **
            Order allow,deny
            Allow from all
         </Directory>
      
      </VirtualHost>
    2. Minimal Required Configuration for example2 Websitein /etc/apache2/vhosts.d/example2.conf
      <VirtualHost 192.168.0.101:80> 
      
         ServerName www.example2.org
         DocumentRoot /srv/www/example2
      
         <Directory "/srv/www/example2">
            Order allow,deny
            Allow from all
         </Directory>
      
      </VirtualHost>
  5. Restart Apache
    # /etc/init.d/apache2 restart
    or
    # rcapache2 restart

    Now access the websites via your favorite web-browser
    DONE 😉

* If the website is host on the default http port i.e port 80 then its optional to specify the port on rhel, but on a SLES, even the default http port(80) must have to be explicitly specify/define.

** On rhel the Directory Block( <Directory “dir_name”> …</Directory> ) declaration is optional, but on a SLES it is must required within Virtual host Configuration( <VirtualHost IP:Port>…</VirtualHost> ).

6 Comments

  1. The Stem Group

    That is really attention-grabbing, You’re an overly professional blogger. I’ve joined your rss feed and sit up for seeking more of your wonderful post. Additionally, I’ve shared your site in my social networks

  2. atlantiscomputing

    I think this is one of the most vital info for me. And i’m satisfied reading your article. But wanna remark on few general things, The site style is ideal, the articles is really nice : D. Good task, cheers

  3. eva

    I don’t even know the way I ended up right here, however I believed this put up was great. I don’t know who you’re but certainly you’re going to a well-known blogger in the event you aren’t already. Cheers!

  4. tarot en femenino

    This page truly has all of the information I wanted about this subject and didn’t know who to ask.

  5. garcinia cambogia benefits

    I really like it when people come together and share ideas. Great website, stick with it!

  6. sohila zadran

    Hmm it appears like your website ate my first comment (it was extremely long) so I guess I’ll just sum it up what I submitted and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog blogger but I’m still new to everything. Do you have any tips and hints for first-time blog writers? I’d really appreciate it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2025 eddie

Theme by Anders NorenUp ↑