GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
* Sign Up! *

Support
Customer Portal
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Virtual Hosting: Multiple Domains on One VPS

bullet Introduction

One of the advantages of a VPS is that you can host many web sites on it. Apache does this with name-based virtual hosting: it serves different content for different domain names, even though they share one IP address. The browser tells Apache which hostname it asked for — via the HTTP Host: header, and for HTTPS via TLS's SNI extension — and Apache picks the matching configuration. This page builds on Apache.

 

bullet Defining a Virtual Host

Create one configuration file per site in the directory Apache includes automatically — /usr/local/etc/apache24/Includes/ on FreeBSD, or /etc/httpd/conf.d/ on Rocky Linux. For example, example.com.conf:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /home/youruser/public_html
    ErrorLog  /var/log/httpd/example.com-error.log
    CustomLog /var/log/httpd/example.com-access.log combined

    <Directory /home/youruser/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

For each additional domain, create another file with its own ServerName, DocumentRoot, and log paths. Apache reads every .conf file in the include directory automatically — there is no central list to maintain. (On FreeBSD the default log location is /var/log/ with names like httpd-example.com-access.log; adjust the paths to match your system.)

Reload Apache after adding or changing a virtual host, testing the configuration first:

# apachectl configtest && service apache24 reload   # FreeBSD
# apachectl configtest && systemctl reload httpd     # Rocky Linux

 

bullet Rocky Linux: SELinux Labels

Serving a site from /home/youruser/public_html rather than under /var/www means SELinux does not consider those files web content by default, and Apache will get "Permission denied" even though ls -l looks correct. Give the tree the right label once — it persists across reboots and relabels:

# semanage fcontext -a -t httpd_sys_content_t "/home/youruser/public_html(/.*)?"
# restorecon -Rv /home/youruser/public_html

(semanage comes from the policycoreutils-python-utils package.) See Web Applications for the read-write label that upload directories need.

 

bullet Per-Directory Overrides and .htaccess

AllowOverride All (used above) lets per-directory .htaccess files override configuration — convenient for clients who manage their own redirects or password-protected directories, and required by many web-application installers. The trade-off is a small performance cost and that anyone who can write to the directory can change Apache's behavior for it. For a site you control entirely yourself, AllowOverride None with the equivalent directives placed directly in the virtual host file is slightly faster and keeps all configuration in one place.

TIP: Webmin's Servers → Apache Webserver module includes a "Create Virtual Host" wizard that writes a file like the one above for you — handy once you are managing several sites. Give each site HTTPS with the HTTPS and SSL page; thanks to SNI, one IP address can serve a certificate per site.

 

bullet Documentation


Toll Free 1-866-GSP-4400 • 1-301-464-9363 • service@gsp.com
Copyright © 1994-2026 GSP Services, Inc.