System Status
Buy Now
  • Email & Apps
  • Office 365
Login
  • MyRackspace Portal
  • Cloud Control Panel
  • Rackspace Webmail Login
  • Cloud Office Control Panel
  • Support Home
  • How-To
  • Developer Documentation
  •  Blogs 
    • Expert Insights Tech Blog
    • Rackspace Blog
    • Solve: Thought Leadership

Support Network

End-to-End Multicloud Solutions.   Solving Together.â„¢   Learn more at Rackspace.com

How–To Home

Cloud Servers

  • Introduction
  • FAQ
  • All Articles

Setup a Name-Based Virtual Host in Apache

Last updated on:  2021-12-02

Authored by:  Rocio Rodriguez


With name-based virtual hosts you can host multiple websites on the same IP / server. Each website will require an unique hostname.

Note: This article assumes that you have installed Apache on your server.

Prerequisites

  • An Apache web server.
  • Access to a Linux privileged user such as root.
  • Access to the DNS records of a domain or subdomain.

Procedure

  1. Login into your server via SSH and switch to root user.

    $ su
    or
    $ sudo -i
    
  2. Go to your Apache site configuration.

    #RHEL and CentOS based distributions:
    # cd /etc/httpd/conf/httpd.conf
    
    #Ubuntu and Debian based distributions:
    # cd /etc/apache2/sites-available
    
  3. Open the configuration file where your site is located.

    Note: This and the following steps may change depending on your configuration. We will assume that you are using the default one.

    # nano 000-default.conf
    

    or

    # vim 000-default.conf
    
  4. Add or edit (if they already exist) the following directives to your desire virtual host.

    Note: You can add as many virtual hosts as you want. However, each one should have a unique server name. If you are using SSL: You should also add these directives to the SSL virtual host, port 443.

    <VirtualHost *:80>
        # Here goes the hostname yu want to connect with:
        ServerName www.example.com 
        # You might want to add an alias (optional):
        ServerAlias example.com 
        # This is the location of your website files:
        DocumentRoot "/www/domain"
    </VirtualHost>
    
  5. Save and close your file. Using Nano: To save: Ctrl + O Enter To exit: Ctrl + X

    Using Vim: Esc :wq Enter

  6. Restart Apache Note: This step can change depending on your OS.

    #RHEL and CentOS based distributions:
    # systemctl restart httpd
    
    #Ubuntu and Debian based distributions:
    # systemctl restart apache2
    
  7. Add an A record on your selected hostname that points to the IP of your server.

Related articles

  • Manage DNS records in the MyRackspace Portal (Dedicated Customers)
  • Create DNS records with Cloud DNS (Cloud Customers)

Use the Feedback tab to make any comments or ask questions. You can also start a conversation with us.

Share this information:

©2020 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER

About Rackspace
  • About
  • Customer Stories
  • Events
  • Programs
Blogs
  • The Rackspace Blog
  • Expert Insights Tech Blog
  • Solve: Thought Leadership
  • News
  • Contact Information
  • Legal
  • Careers
Site Information
  • Style Guide for Technical Content
  • Trademarks
  • Privacy Statement
  • Website Terms
Support Network
  • Support Network Home
  • Rackspace How-To
  • API Documentation
  • Developer Center
  • ©2020 Rackspace US, Inc.