SlideShare a Scribd company logo
1 of 9
Download to read offline
How To Configure Apache VirtualHost on RHEL 7 on AWS
i | P a g e
Table of Contents
Overview.......................................................................................................................................................1
Applies To......................................................................................................................................................1
Pre-Requisites ...............................................................................................................................................1
Configure Apache – VirtualHost....................................................................................................................1
Default – Listen .........................................................................................................................................1
Default – DocumentRoot..........................................................................................................................1
Default – List DocumentRoot....................................................................................................................2
New Website Directory.............................................................................................................................2
Add Listen .................................................................................................................................................2
Add VirtualHost Directive .........................................................................................................................3
Default Port – 80...................................................................................................................................3
Alternate Port – 81................................................................................................................................3
Alternate Port – 82................................................................................................................................3
Parse Config File........................................................................................................................................5
Create – Log Directories............................................................................................................................5
Validate Syntax..........................................................................................................................................5
Parse Config File........................................................................................................................................6
Restart Service – httpd..............................................................................................................................6
SELinux Status ...........................................................................................................................................7
Add Network port type.........................................................................................................................7
Modify Security Group..................................................................................................................................7
Launch websites............................................................................................................................................8
Website #1 ............................................................................................................................................8
Website #2 ............................................................................................................................................8
Website #3 ............................................................................................................................................8
How To Configure Apache VirtualHost on RHEL 7 on AWS
1 | P a g e
Overview
Virtual hosts means hosting more than one website’s on apache webserver.
The purpose of this guide is to configure virtual hosts on a different ports and different document content
folder. It is always a best practice to configure SELinux in enforcing mode to have extra layer of security
on the server that is exposed to the internet domain.
Applies To
Tested on RHEL 7, CentOS 7.
Pre-Requisites
 apache httpd
 policycoreutils-python (semanage command)
Configure Apache – VirtualHost
One of the features with apache is configuring virtualhost for hosting multiple websites on a webserver
and configuring these website on a different ports also.
All the configurations has to be done with “apache” user. Daemon start/restart/status command should
be executed with “root” user.
Default – Listen
Next we will list the “Listen” directive (port to listen) that has been configured. By default this directive is
configured to listen on port “80”; run the command;
cat /etc/httpd/conf/httpd.conf | grep ^Listen
Default – DocumentRoot
First and foremost thing that has to be done is to know the “DocumentRoot” directive that has been
configured in apache main configuration file “httpd.conf”. By default this directive is configured as
“/var/www/html”.
cat /etc/httpd/conf/httpd.conf | grep ^DocumentRoot
How To Configure Apache VirtualHost on RHEL 7 on AWS
2 | P a g e
Default – List DocumentRoot
Next we will list the folder DocumentRoot “/var/www/”, run the command;
cd /var/www/ ; ll
New Website Directory
Create the new website directory, where we intend create new website and change the owner of the
folder to apache user and group.
mkdir -v /var/www/example{2..3}; cd /var/www/
chown -R apache:apache example{2..3} ; ll
Add Listen
Next step is to configure listen port directive, edit “httpd.conf” and add the directive entries as below.
Listen :80
Listen :81
Listen :82
How To Configure Apache VirtualHost on RHEL 7 on AWS
3 | P a g e
Add VirtualHost Directive
Next step is to create a new VirtualHost directive entries for different ports, as below.
Default Port – 80
Configuration directives for port 80 and virtual host.
<VirtualHost *:80>
ServerAdmin admin@domain.com
DocumentRoot "/var/www/html"
ServerName example1.domain.com
ServerAlias example1.domain.com
ErrorLog "/var/log/httpd/example1/error_log"
CustomLog "/var/log/httpd/example1/access_log" common
<Directory /var/www/html>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
Alternate Port – 81
Configuration directives for port 81 and virtual host.
<VirtualHost *:81>
ServerAdmin admin@domain.com
DocumentRoot "/var/www/example2"
ServerName example2.domain.com
ServerAlias example2.domain.com
ErrorLog "/var/log/httpd/example2/error_log"
CustomLog "/var/log/httpd/example2/access_log" common
<Directory /var/www/example2>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
Alternate Port – 82
Configuration directives for port 82 and virtual host.
<VirtualHost *:82>
ServerAdmin admin@domain.com
DocumentRoot "/var/www/example3"
ServerName example3.domain.com
ServerAlias example3.domain.com
ErrorLog "/var/log/httpd/example3/error_log"
CustomLog "/var/log/httpd/example3/access_log" common
<Directory /var/www/example3>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
How To Configure Apache VirtualHost on RHEL 7 on AWS
4 | P a g e
How To Configure Apache VirtualHost on RHEL 7 on AWS
5 | P a g e
Parse Config File
To show the settings as parsed from the config file and show errors in the configuration, run the command;
httpd -S
Note: In this case log file directories are not created, hence the check has failed.
Create – Log Directories
Next step is to create log directories for “example1”, “example2” and “example3” in “/var/log/httpd/”.
In this directory all the access and error logs will be generated and stored, to create these directories run
the command;
mkdir -v /var/log/httpd/example{1..3}
Validate Syntax
After parsing the configuration file, next we will check for syntax errors to validate the syntax, run the
command; if no issues are found “Syntax OK” will be displayed.
httpd -t
How To Configure Apache VirtualHost on RHEL 7 on AWS
6 | P a g e
Parse Config File
After creating the directory, rerun the parse config file and show errors if any, if no errors are reported, it
will list all the main parameters configured.
httpd -S
Restart Service – httpd
After validating the configuration and verifying the syntax, next you can go ahead and restart the httpd
service and check the service status.
systemctl restart httpd
systemctl status httpd -l
How To Configure Apache VirtualHost on RHEL 7 on AWS
7 | P a g e
SELinux Status
To know the SELinux Status and current enforcement mode configured run the command; if the “SeLinux
status” is enabled and current mode is set to “enforcing”; SELinux configuration is required else ignore
these steps.
sestatus | grep 'SELinux status|Current mode'
Add Network port type
Since SELinux is enabled, next step is to add network type port type definitions for SELinux to authorize
ports 80 – 82 for http traffic, run the command.
semanage port -d -t http_port_t -p tcp 80
semanage port -d -t http_port_t -p tcp 81
semanage port -d -t http_port_t -p tcp 82
semanage port -l | grep -w "http_port_t" or semanage port -l | grep http_port_t
Modify Security Group
Add new rules to the “Inbound rules” in the AWS Security group for all the ports that needs to access
from outside.
How To Configure Apache VirtualHost on RHEL 7 on AWS
8 | P a g e
Launch Websites
To demonstrate these settings and configuration is working, we will create a “index.html” file with a
sample html content page as per the website numbers and different font colors.
Website #1
<HTML>
<BODY>
<TITLE> 1st website </TITLE>
<H1>
<FONT COLOR="brown"> This is First website's default page </H1>
</H1>
</BODY>
</HTML>
Website #2
<HTML>
<BODY>
<TITLE> 2nd website </TITLE>
<H1>
<FONT COLOR="green"> This is second website's default page </FONT>
</H1>
</FONT>
</BODY>
</HTML>
Website #3
<HTML>
<BODY>
<TITLE> 3rd website </TITLE>
<H1>
<FONT COLOR="blue"> This is third website's default page </FONT>
</H1>
</FONT>
</BODY>
</HTML>

More Related Content

What's hot

What's hot (20)

How To Install and Configure AWS CLI on RHEL 7
How To Install and Configure AWS CLI on RHEL 7How To Install and Configure AWS CLI on RHEL 7
How To Install and Configure AWS CLI on RHEL 7
 
How To Install and Configure SUDO on RHEL 7
How To Install and Configure SUDO on RHEL 7How To Install and Configure SUDO on RHEL 7
How To Install and Configure SUDO on RHEL 7
 
How to Upgrade Openfire on CentOS 7
How to Upgrade Openfire on CentOS 7How to Upgrade Openfire on CentOS 7
How to Upgrade Openfire on CentOS 7
 
How to Install MariaDB Server or MySQL Server on CentOS 7
How to Install MariaDB Server or MySQL Server on CentOS 7How to Install MariaDB Server or MySQL Server on CentOS 7
How to Install MariaDB Server or MySQL Server on CentOS 7
 
How To Install and Configure Splunk on RHEL 7 in AWS
How To Install and Configure Splunk on RHEL 7 in AWSHow To Install and Configure Splunk on RHEL 7 in AWS
How To Install and Configure Splunk on RHEL 7 in AWS
 
Install and Configure RSyslog – CentOS 7 / RHEL 7
Install and Configure RSyslog – CentOS 7 / RHEL 7Install and Configure RSyslog – CentOS 7 / RHEL 7
Install and Configure RSyslog – CentOS 7 / RHEL 7
 
How to installation and configure apache2
How to installation and configure apache2How to installation and configure apache2
How to installation and configure apache2
 
How To Configure SNMP Logging on RHEL 7
How To Configure SNMP Logging on RHEL 7How To Configure SNMP Logging on RHEL 7
How To Configure SNMP Logging on RHEL 7
 
Install and Configure WordPress in AWS on RHEL 7 or CentOS 7
Install and Configure WordPress in AWS on RHEL 7 or CentOS 7Install and Configure WordPress in AWS on RHEL 7 or CentOS 7
Install and Configure WordPress in AWS on RHEL 7 or CentOS 7
 
How to install and configure firewall on ubuntu os
How to install and configure firewall on ubuntu osHow to install and configure firewall on ubuntu os
How to install and configure firewall on ubuntu os
 
How to Install and Configure Cacti on Linux
How to Install and Configure Cacti on LinuxHow to Install and Configure Cacti on Linux
How to Install and Configure Cacti on Linux
 
Configure Run Levels RHEL 7 or CentOS 7
Configure Run Levels RHEL 7 or CentOS 7Configure Run Levels RHEL 7 or CentOS 7
Configure Run Levels RHEL 7 or CentOS 7
 
How To Install and Configure SNMP on RHEL 7 or CentOS 7
How To Install and Configure SNMP on RHEL 7 or CentOS 7How To Install and Configure SNMP on RHEL 7 or CentOS 7
How To Install and Configure SNMP on RHEL 7 or CentOS 7
 
SystemD Usage Guide
SystemD Usage GuideSystemD Usage Guide
SystemD Usage Guide
 
How To Install and Use ABRT CLI on RHEL 7
How To Install and Use ABRT CLI on RHEL 7How To Install and Use ABRT CLI on RHEL 7
How To Install and Use ABRT CLI on RHEL 7
 
How To Manage Services on RHEL 7 or CentOS 7
How To Manage Services on RHEL 7 or CentOS 7How To Manage Services on RHEL 7 or CentOS 7
How To Manage Services on RHEL 7 or CentOS 7
 
How To Install CentOS 7
How To Install CentOS 7How To Install CentOS 7
How To Install CentOS 7
 
Nginx bind() to 0.0.0.0:9080 failed
Nginx bind() to 0.0.0.0:9080 failedNginx bind() to 0.0.0.0:9080 failed
Nginx bind() to 0.0.0.0:9080 failed
 
LSOF Command Usage on RHEL 7
LSOF Command Usage on RHEL 7LSOF Command Usage on RHEL 7
LSOF Command Usage on RHEL 7
 
TFTP Installation Configuration Guide
TFTP Installation Configuration GuideTFTP Installation Configuration Guide
TFTP Installation Configuration Guide
 

Similar to How To Configure Apache VirtualHost on RHEL 7 on AWS

Similar to How To Configure Apache VirtualHost on RHEL 7 on AWS (20)

Configuration of Apache Web Server On CentOS 8
Configuration of Apache Web Server On CentOS 8Configuration of Apache Web Server On CentOS 8
Configuration of Apache Web Server On CentOS 8
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by Capistrano
 
Apache - Quick reference guide
Apache - Quick reference guideApache - Quick reference guide
Apache - Quick reference guide
 
Apache
ApacheApache
Apache
 
Proxy
ProxyProxy
Proxy
 
L.A.M.P Installation Note --- CentOS 6.5
L.A.M.P Installation Note --- CentOS 6.5L.A.M.P Installation Note --- CentOS 6.5
L.A.M.P Installation Note --- CentOS 6.5
 
Installing lemp with ssl and varnish on Debian 9
Installing lemp with ssl and varnish on Debian 9Installing lemp with ssl and varnish on Debian 9
Installing lemp with ssl and varnish on Debian 9
 
Http
HttpHttp
Http
 
Apache HTTP Server
Apache HTTP ServerApache HTTP Server
Apache HTTP Server
 
Philly security shell meetup
Philly security shell meetupPhilly security shell meetup
Philly security shell meetup
 
Apache Presentation
Apache PresentationApache Presentation
Apache Presentation
 
Apache
ApacheApache
Apache
 
Using aphace-as-proxy-server
Using aphace-as-proxy-serverUsing aphace-as-proxy-server
Using aphace-as-proxy-server
 
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin JonesITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
 
are available here
are available hereare available here
are available here
 
How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7
 
Raj apache
Raj apacheRaj apache
Raj apache
 
Apache Ppt
Apache PptApache Ppt
Apache Ppt
 
Apache Web Server Setup 3
Apache Web Server Setup 3Apache Web Server Setup 3
Apache Web Server Setup 3
 
Document Management: Opendocman and LAMP installation on Cent OS
Document Management: Opendocman and LAMP installation on Cent OSDocument Management: Opendocman and LAMP installation on Cent OS
Document Management: Opendocman and LAMP installation on Cent OS
 

More from VCP Muthukrishna

More from VCP Muthukrishna (20)

How to Fix Duplicate Packages in YUM on CentOS 7
How to Fix Duplicate Packages in YUM on CentOS 7How to Fix Duplicate Packages in YUM on CentOS 7
How to Fix Duplicate Packages in YUM on CentOS 7
 
How To Install and Configure GNome on CentOS 7
How To Install and Configure GNome on CentOS 7How To Install and Configure GNome on CentOS 7
How To Install and Configure GNome on CentOS 7
 
How To Connect to Active Directory User Validation
How To Connect to Active Directory User ValidationHow To Connect to Active Directory User Validation
How To Connect to Active Directory User Validation
 
How To Connect To Active Directory PowerShell
How To Connect To Active Directory PowerShellHow To Connect To Active Directory PowerShell
How To Connect To Active Directory PowerShell
 
How To List Files on Remote Server - PowerShell
How To List Files on Remote Server - PowerShellHow To List Files on Remote Server - PowerShell
How To List Files on Remote Server - PowerShell
 
How To List Files and Display In HTML Format
How To List Files and Display In HTML FormatHow To List Files and Display In HTML Format
How To List Files and Display In HTML Format
 
How To Check and Delete a File via PowerShell
How To Check and Delete a File via PowerShellHow To Check and Delete a File via PowerShell
How To Check and Delete a File via PowerShell
 
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
 
How To Setup SSH Keys on CentOS 7
How To Setup SSH Keys on CentOS 7How To Setup SSH Keys on CentOS 7
How To Setup SSH Keys on CentOS 7
 
How To Install and Configure Open SSH Server on Ubuntu
How To Install and Configure Open SSH Server on UbuntuHow To Install and Configure Open SSH Server on Ubuntu
How To Install and Configure Open SSH Server on Ubuntu
 
Windows PowerShell Basics - How To List PSDrive Info
Windows PowerShell Basics - How To List PSDrive InfoWindows PowerShell Basics - How To List PSDrive Info
Windows PowerShell Basics - How To List PSDrive Info
 
How To List Nginx Modules Installed / Complied on CentOS 7
How To List Nginx Modules Installed / Complied on CentOS 7How To List Nginx Modules Installed / Complied on CentOS 7
How To List Nginx Modules Installed / Complied on CentOS 7
 
Windows PowerShell Basics – How To Create powershell for loop
Windows PowerShell Basics – How To Create powershell for loopWindows PowerShell Basics – How To Create powershell for loop
Windows PowerShell Basics – How To Create powershell for loop
 
How To Construct IF and Else Conditional Statements
How To Construct IF and Else Conditional StatementsHow To Construct IF and Else Conditional Statements
How To Construct IF and Else Conditional Statements
 
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
How To Create PowerShell Function Mandatory Parameter and Optional ParameterHow To Create PowerShell Function Mandatory Parameter and Optional Parameter
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
 
How To Create Power Shell Function Mandatory Parameter Value
How To Create Power Shell Function Mandatory Parameter ValueHow To Create Power Shell Function Mandatory Parameter Value
How To Create Power Shell Function Mandatory Parameter Value
 
How To Create PowerShell Function
How To Create PowerShell FunctionHow To Create PowerShell Function
How To Create PowerShell Function
 
How To Disable IE Enhanced Security Windows PowerShell
How To Disable IE Enhanced Security Windows PowerShellHow To Disable IE Enhanced Security Windows PowerShell
How To Disable IE Enhanced Security Windows PowerShell
 
How To Check IE Enhanced Security Is Enabled Windows PowerShell
How To Check IE Enhanced Security Is Enabled Windows PowerShellHow To Check IE Enhanced Security Is Enabled Windows PowerShell
How To Check IE Enhanced Security Is Enabled Windows PowerShell
 
How To Install and Configure Screen on CentOS 7
How To Install and Configure Screen on CentOS 7How To Install and Configure Screen on CentOS 7
How To Install and Configure Screen on CentOS 7
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

How To Configure Apache VirtualHost on RHEL 7 on AWS

  • 1. How To Configure Apache VirtualHost on RHEL 7 on AWS i | P a g e Table of Contents Overview.......................................................................................................................................................1 Applies To......................................................................................................................................................1 Pre-Requisites ...............................................................................................................................................1 Configure Apache – VirtualHost....................................................................................................................1 Default – Listen .........................................................................................................................................1 Default – DocumentRoot..........................................................................................................................1 Default – List DocumentRoot....................................................................................................................2 New Website Directory.............................................................................................................................2 Add Listen .................................................................................................................................................2 Add VirtualHost Directive .........................................................................................................................3 Default Port – 80...................................................................................................................................3 Alternate Port – 81................................................................................................................................3 Alternate Port – 82................................................................................................................................3 Parse Config File........................................................................................................................................5 Create – Log Directories............................................................................................................................5 Validate Syntax..........................................................................................................................................5 Parse Config File........................................................................................................................................6 Restart Service – httpd..............................................................................................................................6 SELinux Status ...........................................................................................................................................7 Add Network port type.........................................................................................................................7 Modify Security Group..................................................................................................................................7 Launch websites............................................................................................................................................8 Website #1 ............................................................................................................................................8 Website #2 ............................................................................................................................................8 Website #3 ............................................................................................................................................8
  • 2. How To Configure Apache VirtualHost on RHEL 7 on AWS 1 | P a g e Overview Virtual hosts means hosting more than one website’s on apache webserver. The purpose of this guide is to configure virtual hosts on a different ports and different document content folder. It is always a best practice to configure SELinux in enforcing mode to have extra layer of security on the server that is exposed to the internet domain. Applies To Tested on RHEL 7, CentOS 7. Pre-Requisites  apache httpd  policycoreutils-python (semanage command) Configure Apache – VirtualHost One of the features with apache is configuring virtualhost for hosting multiple websites on a webserver and configuring these website on a different ports also. All the configurations has to be done with “apache” user. Daemon start/restart/status command should be executed with “root” user. Default – Listen Next we will list the “Listen” directive (port to listen) that has been configured. By default this directive is configured to listen on port “80”; run the command; cat /etc/httpd/conf/httpd.conf | grep ^Listen Default – DocumentRoot First and foremost thing that has to be done is to know the “DocumentRoot” directive that has been configured in apache main configuration file “httpd.conf”. By default this directive is configured as “/var/www/html”. cat /etc/httpd/conf/httpd.conf | grep ^DocumentRoot
  • 3. How To Configure Apache VirtualHost on RHEL 7 on AWS 2 | P a g e Default – List DocumentRoot Next we will list the folder DocumentRoot “/var/www/”, run the command; cd /var/www/ ; ll New Website Directory Create the new website directory, where we intend create new website and change the owner of the folder to apache user and group. mkdir -v /var/www/example{2..3}; cd /var/www/ chown -R apache:apache example{2..3} ; ll Add Listen Next step is to configure listen port directive, edit “httpd.conf” and add the directive entries as below. Listen :80 Listen :81 Listen :82
  • 4. How To Configure Apache VirtualHost on RHEL 7 on AWS 3 | P a g e Add VirtualHost Directive Next step is to create a new VirtualHost directive entries for different ports, as below. Default Port – 80 Configuration directives for port 80 and virtual host. <VirtualHost *:80> ServerAdmin admin@domain.com DocumentRoot "/var/www/html" ServerName example1.domain.com ServerAlias example1.domain.com ErrorLog "/var/log/httpd/example1/error_log" CustomLog "/var/log/httpd/example1/access_log" common <Directory /var/www/html> Options FollowSymLinks AllowOverride None Require all granted </Directory> </VirtualHost> Alternate Port – 81 Configuration directives for port 81 and virtual host. <VirtualHost *:81> ServerAdmin admin@domain.com DocumentRoot "/var/www/example2" ServerName example2.domain.com ServerAlias example2.domain.com ErrorLog "/var/log/httpd/example2/error_log" CustomLog "/var/log/httpd/example2/access_log" common <Directory /var/www/example2> Options FollowSymLinks AllowOverride None Require all granted </Directory> </VirtualHost> Alternate Port – 82 Configuration directives for port 82 and virtual host. <VirtualHost *:82> ServerAdmin admin@domain.com DocumentRoot "/var/www/example3" ServerName example3.domain.com ServerAlias example3.domain.com ErrorLog "/var/log/httpd/example3/error_log" CustomLog "/var/log/httpd/example3/access_log" common <Directory /var/www/example3> Options FollowSymLinks AllowOverride None Require all granted </Directory> </VirtualHost>
  • 5. How To Configure Apache VirtualHost on RHEL 7 on AWS 4 | P a g e
  • 6. How To Configure Apache VirtualHost on RHEL 7 on AWS 5 | P a g e Parse Config File To show the settings as parsed from the config file and show errors in the configuration, run the command; httpd -S Note: In this case log file directories are not created, hence the check has failed. Create – Log Directories Next step is to create log directories for “example1”, “example2” and “example3” in “/var/log/httpd/”. In this directory all the access and error logs will be generated and stored, to create these directories run the command; mkdir -v /var/log/httpd/example{1..3} Validate Syntax After parsing the configuration file, next we will check for syntax errors to validate the syntax, run the command; if no issues are found “Syntax OK” will be displayed. httpd -t
  • 7. How To Configure Apache VirtualHost on RHEL 7 on AWS 6 | P a g e Parse Config File After creating the directory, rerun the parse config file and show errors if any, if no errors are reported, it will list all the main parameters configured. httpd -S Restart Service – httpd After validating the configuration and verifying the syntax, next you can go ahead and restart the httpd service and check the service status. systemctl restart httpd systemctl status httpd -l
  • 8. How To Configure Apache VirtualHost on RHEL 7 on AWS 7 | P a g e SELinux Status To know the SELinux Status and current enforcement mode configured run the command; if the “SeLinux status” is enabled and current mode is set to “enforcing”; SELinux configuration is required else ignore these steps. sestatus | grep 'SELinux status|Current mode' Add Network port type Since SELinux is enabled, next step is to add network type port type definitions for SELinux to authorize ports 80 – 82 for http traffic, run the command. semanage port -d -t http_port_t -p tcp 80 semanage port -d -t http_port_t -p tcp 81 semanage port -d -t http_port_t -p tcp 82 semanage port -l | grep -w "http_port_t" or semanage port -l | grep http_port_t Modify Security Group Add new rules to the “Inbound rules” in the AWS Security group for all the ports that needs to access from outside.
  • 9. How To Configure Apache VirtualHost on RHEL 7 on AWS 8 | P a g e Launch Websites To demonstrate these settings and configuration is working, we will create a “index.html” file with a sample html content page as per the website numbers and different font colors. Website #1 <HTML> <BODY> <TITLE> 1st website </TITLE> <H1> <FONT COLOR="brown"> This is First website's default page </H1> </H1> </BODY> </HTML> Website #2 <HTML> <BODY> <TITLE> 2nd website </TITLE> <H1> <FONT COLOR="green"> This is second website's default page </FONT> </H1> </FONT> </BODY> </HTML> Website #3 <HTML> <BODY> <TITLE> 3rd website </TITLE> <H1> <FONT COLOR="blue"> This is third website's default page </FONT> </H1> </FONT> </BODY> </HTML>