VOOZH about

URL: https://thenewstack.io/configure-multiple-websites-on-a-single-rhel-based-apache-host/

⇱ Configure Multiple Websites on a Single RHEL-Based Apache Host - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2023-12-16 06:00:33
Configure Multiple Websites on a Single RHEL-Based Apache Host
Linux

Configure Multiple Websites on a Single RHEL-Based Apache Host

At some point, in your development or admin career, you're going to have to host more than one website on a single server, virtual machine, or even container, probably using the Apache HTTP Server. Here is how.
Dec 16th, 2023 6:00am by Jack Wallen
👁 Featued image for: Configure Multiple Websites on a Single RHEL-Based Apache Host
Feature image courtesy of the Apache Software Foundation.

At some point, in your development or admin career, you’re going to have to host more than one website on a single server, virtual machine, or even container, probably using the Apache HTTP Server. When that happens, you have a few options at your disposal. You could deploy each website as a separate container or you could go the old-school route and use Apache’s virtual host option.

Sure, there are better ways to do this now but Apache virtual hosts is one of the most reliable methods and it’s also a skill you’ll be glad you have. Not only will it get you better acquainted with the web server you’ll also up your Linux game in the process (and who doesn’t want or need that)?

Say, for example, you need to host more than one internal site (say, one for HR and one for CRM) and you need to do it on the same server. This is possible with Apache virtual hosts.

Let me show you how this is done.

What You Need

To follow along, you’ll need the following things:

  • A machine with a RHEL-based OS installed (such as Red Hat Enterprise Linux, Rocky Linux, AlmaLinux, CentOS Stream, or Oracle Linux).
  • A user with sudo privileges.
  • An FQDN with your network hardware directing that domain to the hosting server. For this example, we’ll use the domains newstackexample1.com and newstackexample2.com. Keep in mind that you’ll need to replace these domains with whatever domains you’ve chosen.

That’s it. Let’s get to work.

Create the Required Directories

The first thing we must do is create the directories that will house our virtual hosts. Log into your server and (if necessary) open a terminal window. We’re going to create directories named newstackexample1.com and newstackexample2.com with the following commands:

sudo mkdir -p /var/www/newstackexample1.com

sudo mkdir -p /var/www/newstackexample2.com

With our directories created, we then need to change the ownership so they belong to the apache user and group. This can be done with the following commands:

sudo chown apache:apache -R /var/www/newstackexample1.com


sudo chown apache:apache -R /var/www/newstackexample2.com

Outstanding.

Create index.html Files for Each Virtual Host

Our next task is to create index files for each virtual host. These two files will both be named index.html.

Create the first file with the command:

sudo nano /var/www/newstackexample1.com/index.html

In that file, paste the following:

Save and close the file.

Create the second file with:

sudo nano /var/www/newstackexample2.com/index.html

In that file, paste the following:

Save and close the file.

Configuring the Virtual Hosts

The next step is to create the virtual hosts file for each of our new sites. We’ll create the file for web1 with the command:

sudo nano /etc/http/conf.d/newstackexample1.conf

In that file, paste the following:

Save and close the file.

It’s important to note that ServerName will be your domain name (such as newstackexample1.com) and ServerAlias will be an alternate name that is also accepted by the server (such as www.newstackexample1.com or mail.newstackexample1.com).

Create the virtual host config file for the second host with the command:

sudo nano /etc/http/conf.d/newstackexample2.conf

In that file, paste the following:

Save and close the file.

With our indexes and configuration files created, restart Apache with the command:

sudo systemctl restart httpd

The Apache service should restart without complaint.

Opening the Firewall

By default, your firewall is most likely not configured to allow HTTP traffic through. To open the firewall for port 80, issue the command:

sudo firewall-cmd --zone=public --add-service=http --permanent

Reload the firewall with:

sudo firewall-cmd --reload

Configure SELinux

Because we’re using a RHEL-based distribution, we also have to deal with the SELinux security framework. Unless you take care of this, traffic will not be able to reach the directories housing the websites. To fix this, issue the following commands:

sudo chcon -R -t httpd_sys_rw_content_t /var/www/newstackexample1.com
sudo chcon -R -t httpd_sys_rw_content_t /var/www/newstackexample2.com

Accessing the Sites

With everything in place (including your network hardware directing the domains to the correct server IP address), you should now be able to view the sites by pointing your browser to either newstackexample1.com or newstackexample2.com. When newstackexample1.com loads you should see Welcome to New Stack Example 1 and when newstackexample2.com loads you should see Welcome to New Stack Example 2.

Congratulations, you’ve just deployed your first virtual hosts with the Apache web server and a RHEL-based Linux distribution. This skill can be very helpful when you need to host multiple internal sites or even external sites for different clients on the same server.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
Oracle and Red Hat are sponsors of The New Stack.  
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.