Apache Virtual Hosting: IP Based and Name Based Virtual Hosts in RHEL/CentOS/Fedora

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Use our Linode referral link if you plan to buy VPS (it starts at only $10/month).
  4. Support us via PayPal donate - Make a Donation
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Tarunika Shrivastava

I am a linux server admin and love to play with Linux and all other distributions of it. I am working as System Engineer with a Web Hosting Company.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

44 Responses

  1. Mallikarjuna reddy says:

    Hi, thanks for the material but thing is I followed the steps what you provided for name-based web server but I am not able to get the output can you please provide the full clear material to my mail mallireddy654@gmail.com

    • Ravi Saive says:

      @Mallikarjuna,

      What output you getting and where? could you share here so that we can provide more better solution on Apache named-based setup.

  2. ki says:

    Purpose of implementing IP based virtual hosting is to assign implementing for each domain and that particular IP will not be used by any other domain. *didn’t understand*

  3. arun natarajan says:

    I have tried your steps, but not able to see the output. config files are correct, services are running, selinux is disabled, still no success.

    Please let me know the step to get output. my workaround.

    [root@suman oracle]$ uname -a
    Linux suman.example.com 2.6.32-71.el6.x86_64 #1 SMP Wed Sep 1 01:33:01 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
    [root@suman oracle]$
    [root@suman oracle]$ httpd -t
    Syntax OK
    [root@suman oracle]$
    [root@suman oracle]$ service httpd status
    httpd (pid  2057) is running...
    [root@suman oracle]$
    

    Example1.com output

    [root@suman oracle]$ cat /var/www/html/example1.com/index.html
    hi suman
    welcome to linux training
    

    Example1.com Output

    [root@suman oracle]$ cat /var/www/html/example2.com/index.html
    www.example2.com
    welcome to example2 website
    
    • Ravi Saive says:

      @Arun,

      May I know what output you getting while accessing these domains via web browser? Also could you share your VirtualHost configuration for these domains in httpd.conf file?

  4. Norbert says:

    Hello,
    I have one domain, do I need to add my IP address of server to their control panel (for their DNS ) ?

    Do I need to install DNS server or apache is enough ?

    Thank you

    Norbert

    • Ravi Saive says:

      @Norbert,

      Just point the domain to IP address of the server in your Hosting DNS control panel, no need to install DNS server, onl Apache is enough to run your website..

  5. Arjun Pawar says:

    i want to redirect my website from http to https. i changed many configuration like .htaccess file and httpd file but i am not getting solution. could help me.

    • Ravi Saive says:

      @Arjun,

      Create a .htaccess file in root of domain or website that you want to redirect to HTTPS and add the following rules.

      RewriteEngine On
      RewriteCond %{HTTPS} off
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
      
      • Arjun Pawar says:

        I have already added this code in .htaccess file in website root but i am not getting solution. i want to know you i am also unable to open website in local network from http with domain name but i able open http with ip domain address.

        • Ravi Saive says:

          @Arjun,

          Make sure that “AllowOverride All” is set in your httpd.conf file and also make sure you have added DNS ‘A’ record for you domain and point back to the server IP address.

  6. Widyachacra says:

    No it shouldn’t be the same hostname.

    You don’t have to use the same local FQDN as your vhost FQDN(ServerName). Create an ‘CNAME’ record lets say ‘www2 CNAME http://www.example1.com‘ & put the ServerName www2.example1.com. Thats all. 8-)

  7. Mrutyunjaya says:

    hii.. please help me . i want to know what is your FQDN name. if your FQDN is http://www.example1.com then, is your host name is www ???

    • Bhasker says:

      I expect FQDN can be example1.mycompany.com then domain is mycompany and example1 is host name. FQDN is nothing but host name along with domain name.

Got something to say? Join the discussion.

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

Join Over 300K+ Linux Users
  1. 177,942
  2. 8,310
  3. 37,548

Are you subscribed?