• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

Apache for Newbie: Set up Apache with mod_vhost_alias

December 17, 2023

Apache for Newbie: Set up Apache with mod_vhost_alias

When it comes to hosting websites, Apache is one of the most popular and widely used web servers. It is known for its flexibility, reliability, and ease of use. In this article, we will explore how to set up Apache with mod_vhost_alias, a powerful module that allows for dynamic virtual hosting.

What is mod_vhost_alias?

Mod_vhost_alias is an Apache module that provides a way to dynamically map virtual hosts to directories. This means that you can host multiple websites on a single Apache server without having to create separate virtual host configurations for each site. Instead, you can use placeholders in your configuration file to dynamically map incoming requests to the appropriate directory.

Setting up mod_vhost_alias

To set up mod_vhost_alias, you need to have Apache installed on your server. If you haven’t already installed Apache, you can follow the instructions on the Server.HK website to get started.

Once Apache is installed, you can enable mod_vhost_alias by running the following command:

sudo a2enmod vhost_alias

This command enables the mod_vhost_alias module and creates a symbolic link in the Apache configuration directory.

Configuring mod_vhost_alias

After enabling mod_vhost_alias, you need to configure it to map virtual hosts to directories. This can be done by editing the Apache configuration file, usually located at /etc/apache2/apache2.conf or /etc/httpd/httpd.conf.

Open the configuration file in a text editor and add the following lines:

UseCanonicalName Off
VirtualDocumentRoot /var/www/%0/public_html

The UseCanonicalName Off directive tells Apache to use the requested hostname as-is, without any canonicalization. The VirtualDocumentRoot directive specifies the directory structure for the virtual hosts. In this example, the virtual hosts are mapped to the /var/www/ directory, with the hostname as the subdirectory.

Save the configuration file and restart Apache for the changes to take effect:

sudo service apache2 restart

Creating Virtual Hosts

With mod_vhost_alias configured, you can now create virtual hosts by simply creating directories under the specified directory structure. For example, to create a virtual host for example.com, you would create the directory /var/www/example.com/public_html and place your website files inside it.

You can create as many virtual hosts as you need, and Apache will automatically serve the correct content based on the requested hostname.

Summary

Setting up Apache with mod_vhost_alias allows for dynamic virtual hosting, making it easier to host multiple websites on a single server. By using placeholders in the Apache configuration file, you can map incoming requests to the appropriate directory without the need for separate virtual host configurations. This not only simplifies the setup process but also improves the scalability and flexibility of your hosting environment.

If you’re looking for reliable and affordable VPS hosting in the Hong Kong, consider Server.HK. With their Hong Kong VPS Hosting plans, you can enjoy the benefits of a virtual private server with high performance and excellent customer support.

Recent Posts

  • How to Run a SaaS Product on Hong Kong VPS: Architecture and Deployment Guide 2026
  • Hong Kong VPS Uptime and SLA: What 99.9% Uptime Really Means for Your Business (2026)
  • Cryptocurrency and USDT Payment for VPS Hosting: Why It Matters for Global Businesses (2026)
  • How to Speed Up Your Website for China: A Technical Optimization Guide 2026
  • Hong Kong VPS Windows Server: How to Set Up and Use a Windows VPS in Asia (2026)

Recent Comments

  1. Hong Kong VPS Uptime and SLA: What 99.9% Uptime Really Means for Your Business (2026) - Server.HK on How to Monitor Your Hong Kong VPS: Uptime, Performance, and Alert Setup Guide (2026)
  2. Best Hong Kong VPS Providers in 2026: Compared by Speed, Routing, and Value - Server.HK on How to Migrate Your Website to a Hong Kong VPS: Zero-Downtime Transfer Guide (2026)
  3. vibramycin injection on How to Choose the Right Hong Kong VPS Plan: A Buyer’s Guide for 2026
  4. allopurinol for gout on CN2 GIA vs BGP vs CN2 GT: What’s the Real Difference for China Connectivity?
  5. antibiotics online purchase on How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot