SlideShare a Scribd company logo
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

PDF
How To Configure FirewallD on RHEL 7 or CentOS 7
PDF
How To Install and Configure VSFTPD on RHEL 7 or CentOS 7
PDF
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
PDF
Installation CentOS 6.3
PDF
How To Protect SSH Access with Fail2Ban on RHEL 7
PDF
How To Install OpenFire in CentOS 7
PDF
How to Change Hostname in CentOS 7 or RHEL 7
PDF
How To Install and Configure Apache SSL on CentOS 7
How To Configure FirewallD on RHEL 7 or CentOS 7
How To Install and Configure VSFTPD on RHEL 7 or CentOS 7
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
Installation CentOS 6.3
How To Protect SSH Access with Fail2Ban on RHEL 7
How To Install OpenFire in CentOS 7
How to Change Hostname in CentOS 7 or RHEL 7
How To Install and Configure Apache SSL on CentOS 7

What's hot (20)

PDF
How To Install and Configure AWS CLI on RHEL 7
PDF
How To Install and Configure SUDO on RHEL 7
PDF
How to Upgrade Openfire on CentOS 7
PDF
How to Install MariaDB Server or MySQL Server on CentOS 7
PDF
How To Install and Configure Splunk on RHEL 7 in AWS
PDF
Install and Configure RSyslog – CentOS 7 / RHEL 7
PDF
How to installation and configure apache2
PDF
How To Configure SNMP Logging on RHEL 7
PDF
Install and Configure WordPress in AWS on RHEL 7 or CentOS 7
PDF
How to install and configure firewall on ubuntu os
PDF
How to Install and Configure Cacti on Linux
PDF
Configure Run Levels RHEL 7 or CentOS 7
PDF
How To Install and Configure SNMP on RHEL 7 or CentOS 7
PDF
SystemD Usage Guide
PDF
How To Install and Use ABRT CLI on RHEL 7
PDF
How To Manage Services on RHEL 7 or CentOS 7
PDF
How To Install CentOS 7
PDF
Nginx bind() to 0.0.0.0:9080 failed
PDF
LSOF Command Usage on RHEL 7
PDF
TFTP Installation Configuration Guide
How To Install and Configure AWS CLI on RHEL 7
How To Install and Configure SUDO on RHEL 7
How to Upgrade Openfire 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
Install and Configure RSyslog – CentOS 7 / RHEL 7
How to installation and configure apache2
How To Configure SNMP Logging on RHEL 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 Cacti on Linux
Configure Run Levels RHEL 7 or CentOS 7
How To Install and Configure SNMP on RHEL 7 or CentOS 7
SystemD Usage Guide
How To Install and Use ABRT CLI on RHEL 7
How To Manage Services on RHEL 7 or CentOS 7
How To Install CentOS 7
Nginx bind() to 0.0.0.0:9080 failed
LSOF Command Usage on RHEL 7
TFTP Installation Configuration Guide
Ad

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

PDF
Configuration of Apache Web Server On CentOS 8
PPT
Deploy Rails Application by Capistrano
PDF
Apache - Quick reference guide
PPT
Apache
PPTX
PDF
L.A.M.P Installation Note --- CentOS 6.5
PDF
How to Install Apache on Debian 12 Server
DOCX
Installing lemp with ssl and varnish on Debian 9
PPT
PPT
Apache HTTP Server
PDF
Philly security shell meetup
PPT
Apache Presentation
PPT
Apache
PDF
Using aphace-as-proxy-server
PDF
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
PPT
are available here
PDF
How To Configure Nginx Load Balancer on CentOS 7
PPT
Raj apache
PPT
Apache Ppt
PPT
Apache Web Server Setup 3
Configuration of Apache Web Server On CentOS 8
Deploy Rails Application by Capistrano
Apache - Quick reference guide
Apache
L.A.M.P Installation Note --- CentOS 6.5
How to Install Apache on Debian 12 Server
Installing lemp with ssl and varnish on Debian 9
Apache HTTP Server
Philly security shell meetup
Apache Presentation
Apache
Using aphace-as-proxy-server
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
are available here
How To Configure Nginx Load Balancer on CentOS 7
Raj apache
Apache Ppt
Apache Web Server Setup 3
Ad

More from VCP Muthukrishna (20)

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

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Getting Started with Data Integration: FME Form 101
PDF
Encapsulation theory and applications.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Approach and Philosophy of On baking technology
PDF
Electronic commerce courselecture one. Pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Weekly Chronicles - August'25-Week II
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A comparative analysis of optical character recognition models for extracting...
MYSQL Presentation for SQL database connectivity
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
Getting Started with Data Integration: FME Form 101
Encapsulation theory and applications.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Advanced methodologies resolving dimensionality complications for autism neur...
Approach and Philosophy of On baking technology
Electronic commerce courselecture one. Pdf
Big Data Technologies - Introduction.pptx
cuic standard and advanced reporting.pdf
Machine learning based COVID-19 study performance prediction
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

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 [email protected] 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 [email protected] 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 [email protected] 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>