• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to implement multiple virtual hosts on Ubuntu 21.04

  • 00:30 lsb_release -a
  • 00:36 sudo -s
  • 00:49 apt install apache2
  • 01:00 cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example1.com.conf
  • 01:31 cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example2.com.conf
  • 02:02 vi /etc/apache2/sites-available/example1.com.conf
  • 02:55 vi /etc/apache2/sites-available/example2.com.conf
  • 03:26 mkdir /var/www/html/example1
  • 03:46 mkdir /var/www/html/example2
  • 04:00 vi /var/www/html/example1/index.html
  • 05:48 a2ensite example2.com.conf
  • 06:00 systemctl restart apache2
  • 06:07 vi /etc/hosts
{{postValue.id}}

To Implement Multiple Virtual Hosts on Ubuntu 21.04

Introduction

In Apache, virtual hosting is the concept of hosting multiple sites within a single server, there are two types of virtual hosting, IP address hosting and domain hosting, so we can host either IP addresses or domain names.

Installation Procedure:

Check the OS version

linuxhelp@linuxhelp:~$ lsb_release -a

Changing as root user

linuxhelp@linuxhelp:~$ sudo -s

Changing the directory to root

root@linuxhelp:/home/linuxhelp# cd / 

Installing apache web server

root@linuxhelp:/# apt install apache2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
0 upgraded, 8 newly installed, 0 to remove and 254 not upgraded.
Need to get 1,739 kB of archives.
After this operation, 7,550 kB of additional disk space will be used.

Copying the default virtual host .conf file example1.com virtual host

root@linuxhelp:/# cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example1.com.conf

Copying the default virtual host .conf file example2.com virtual host

root@linuxhelp:/# cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example2.com.conf

Configure the virtual host for example1.com

root@linuxhelp:/# vi /etc/apache2/sites-available/example1.com.conf 

Snap 1 Configure the virtual host for example2.com

root@linuxhelp:/# vi /etc/apache2/sites-available/example2.com.conf 

Snap 2

Making document Root directory as example1

root@linuxhelp:/# mkdir /var/www/html/example1

Making document Root directory as example2

root@linuxhelp:/# mkdir /var/www/html/example2

Making the index.html file for example1.com

root@linuxhelp:/# vi /var/www/html/example1/index.html

Snap 3

Making the index.html file for example1.com

root@linuxhelp:/# vi /var/www/html/example2/index.html

Snap 4

Enabling virtual host site example1.com.

root@linuxhelp:/# a2ensite example1.com.conf
Enabling site example1.com.
To activate the new configuration, you need to run:
  systemctl reload apache2

Enabling virtual host site example2.com.

root@linuxhelp:/# a2ensite example2.com.conf
Enabling site example2.com.
To activate the new configuration, you need to run:
  systemctl reload apache2

Restart the apache server

root@linuxhelp:/# systemctl restart apache2

Put host entries for virtual hosts

root@linuxhelp:/# vi /etc/hosts

Snap 5

Ping the www.example1.com Snap 6

Ping the www.example1.com Snap 7

With this the implement of multiple virtual hosts comes to an end.

Tags:
landon
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is a virtual host example?

A

Name-based virtual hosts use multiple hostnames for the same IP address.. For instance, a blog server may host both blog1.example.com and blog2.example.com. The biggest issue with name-based virtual hosting is that it is difficult to host multiple secure websites running SSL/TLS.

Q

How many virtual hosts can Apache handle?

A

If each virtual host has its own log, the limit is likely 64 due to file descriptor limits. However, you can configure Apache to run more using this guide

Q

Where is the Apache virtual host file?

A

By default on Ubuntu systems, Apache Virtual Hosts configuration files are stored in /etc/apache2/sites-available directory and can be enabled by creating symbolic links to the /etc/apache2/sites-enabled directory.25-Mar-2019

Q

How do I get Apache to listen on multiple ports?

A

Open configure file /etc/httpd/conf/httpd. conf and modify the Listen directive tells the server to accept incoming requests on the specified port. Multiple Listen directives may be used to specify the number of ports to listen.

Q

What is Mod_vhost_alias?

A

mod_vhost_alias. The VirtualDocumentRoot directive allows you to determine where Apache HTTP Server will find your documents based on the value of the server name.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Luk Van De Looverbosch ?
How to create a root ?

Hello,
How to create root@linuxhelp in Linux Mint 20.1 64-bit ?
Thanks in advance for your reply.
Best regards.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.