A simple Apache-based setup for hosting multiple static websites on a single Ubuntu server using virtual hosts.
- Ubuntu server (20.04 or later recommended)
- Root or sudo access
- Basic familiarity with terminal commands
First, update your package list and install Apache2 and Git:
sudo apt update
sudo apt install -y apache2 git net-toolsVerify Apache2 is running:
sudo systemctl status apache2Check your server's IP address:
ifconfigClone this repository to your local machine:
git clone https://github.com/suhaasd/multisite-static-server.gitCopy the sites to the Apache web root with different names:
cd multisite-static-server
sudo cp -rf site-1 /var/www/html/
sudo cp -rf site-2 /var/www/html/Edit the Apache default configuration file:
sudo nano /etc/apache2/sites-available/000-default.confReplace the contents with the following configuration:
<VirtualHost *:80>
ServerName www.site-1.local
ServerAlias site-1.local
DocumentRoot /var/www/html/site-1
ErrorLog ${APACHE_LOG_DIR}/error. log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName www.site-2.local
ServerAlias site-2.local
DocumentRoot /var/www/html/site-2
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access. log combined
</VirtualHost>Save and exit: Press CTRL + O, then ENTER to save, and CTRL + X to exit nano.
Edit your hosts file to map domain names to your server's IP:
sudo nano /etc/hostsAdd the following lines (replace YOUR_SERVER_IP with your actual IP from Step 1):
YOUR_SERVER_IP site-1.local www.site-1.local
YOUR_SERVER_IP site-2.local www.site-2.local
Example:
192.168.1.100 site-1.local www.site-1.local
192.168.1.100 site-2.local www.site-2.local
Save and exit: Press CTRL + O, then ENTER to save, and CTRL + X to exit nano.
Apply the configuration changes by restarting Apache:
sudo systemctl restart apache2Verify Apache restarted successfully:
sudo systemctl status apache2Open your web browser and navigate to:
- Site 1: http://site-1.local or http://www.site-1.local
- Site 2: http://site-2.local or http://www.site-2.local