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. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  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...

48 Responses

  1. rajendra says:

    I am not getting the line NameVirtualHost in vi /etc/httpd/conf/httpd.conf file.

  2. Zero says:

    there is no httpd.conf and no httpd to install as
    PRETTY_NAME=”Debian GNU/Linux 9 (stretch)”
    NAME=”Debian GNU/Linux”
    VERSION=”9 (stretch)”
    when try to install it
    sudo apt install httpd
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package httpd is a virtual package provided by:
    apache2 2.4.25-3+deb9u2
    yaws 2.0.4+dfsg-1
    webfs 1.21+ds1-12
    tntnet 2.2.1-3+b1
    ocsigenserver 2.7-1+b4
    nginx-light 1.10.3-1+deb9u1
    nginx-full 1.10.3-1+deb9u1
    nginx-extras 1.10.3-1+deb9u1
    mini-httpd 1.23-1.2
    micro-httpd 20051212-15.1
    lighttpd 1.4.45-1
    ebhttpd 1:1.0.dfsg.1-4.3+b2
    aolserver4-daemon 4.5.1-18.1
    aolserver4-core 4.5.1-18.1
    You should explicitly select one to install.

    E: Package ‘httpd’ has no installation candidate

  3. Mirzet Kadic says:

    Isn’t it better to use /var/www/domain.tld/public_html instead of /var/www/html/domain.tld/public_html because 000-default.conf points to /var/www/html and if enabled you can jump to other sites document if you know the folder name.

  4. 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 [email protected]

    • Ravi Saive says:


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

  5. 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*

  6. 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.

    [[email protected] 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
    [[email protected] oracle]$
    [[email protected] oracle]$ httpd -t
    Syntax OK
    [[email protected] oracle]$
    [[email protected] oracle]$ service httpd status
    httpd (pid  2057) is running...
    [[email protected] oracle]$

    Example1.com output

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

    Example1.com Output

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


      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?

  7. Norbert says:

    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


    • Ravi Saive says:


      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..

  8. 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:


      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:


          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.

  9. 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-)

  10. 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 *

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