RHEL 7 Apache Web Server
RHEL 7 Apache Web Server
Advantages:
It support virtual Hosting with 1 Server with 1 IP-ADDRESS multiple
website can be posted.
1
Listen :
If server have multiple IP address, you can limit the IP address and
port on which the server can listen for incoming connection. By
default server listen on port 80, but can be update as well.
DocumentRoot :
Allow :
2
Deny from [IP Deny from 192.168.56.110 To Deny only a specific
Address] IP or host
Service
Packages:httpd,httpd-tools,httpd-manual
Daemon:/usr/lib/systemd/system/httpd.service
Ports:80(http),443(https)
Configuration :/etc/httpd/conf/httpd.conf,/var/www/*
Installation
1. On all node in the cluster (or nodes in the failover domain, if
used), install the httpd httpd-tools httpd-manual
3
---> Package httpd.x86_64 0:2.4.6-67.el7.centos will be installed
--> Processing Dependency: /etc/mime. types for package: httpd-2.4.6-
67.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package:
httpd-2.4.6-67.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-
2.4.6-67.el7.centos.x86_64
---> Package httpd-manual.noarch 0:2.4.6-67.el7.centos will be
installed
---> Package httpd-tools.x86_64 0:2.4.6-67.el7.centos will be
installed
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
4
Package Arch
Version Repository
Size
======================================================================
======================================================================
============================
Installing:
httpd x86_64
2.4.6-67.el7.centos base
2.7 M
httpd-manual noarch
2.4.6-67.el7.centos base
1.3 M
httpd-tools x86_64
2.4.6-67.el7.centos base
87 k
Installing for dependencies:
apr x86_64
1.4.8-3.el7 base
103 k
apr-util x86_64
1.5.2-6.el7 base
92 k
mailcap noarch
2.1.41-2.el7 base
31 k
Transaction Summary
======================================================================
======================================================================
============================
Install 3 Packages (+3 Dependent packages)
5
| 31 kB 00:00:00
-----------------------------------------------------------------------
-----------------------------------------------------------------------
--------------------------
Total
5.3 MB/s | 4.3 MB 00:00:00
Running transaction check
6/6
Installed:
httpd.x86_64 0:2.4.6-67.el7.centos httpd-
manual.noarch 0:2.4.6-67.el7.centos httpd-tools.x86_64
0:2.4.6-67.el7.centos
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64
0:1.5.2-6.el7 mailcap.noarch 0:2.1.41-2.el7
Complete!
[root@server ~]#
Dependencies Resolved
===================================================================
Package Arch
Version Repository
Size
===================================================================
6
Installing:
mod_ssl x86_64
1:2.4.6-67.el7.centos base
108 k
Transaction Summary
===================================================================
Install 1 Package
Complete!
[root@server conf.d]#
7
---> Package nss_compat_ossl.x86_64 0:0.9.6-8.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================
=========
Package Arch Version
Repository Size
=======================================================================
=========
Installing:
elinks x86_64 0.12-0.36.pre6.el7 base
882 k
Installing for dependencies:
js x86_64 1:1.8.5-19.el7 base
2.3 M
nss_compat_ossl x86_64 0.9.6-8.el7 base
37 k
Transaction Summary
=======================================================================
=========
Install 1 Package (+2 Dependent packages)
elinks-0.12-0.36.pre6.el7.x86_64.rpm | 882 kB 0
-----------------------------------------------------------------------
---------
Total 4.3 MB/s | 3.2 MB
00:00
Verifying : nss_compat_ossl-0.9.6-8.el7.x86_64
3/3
Installed:
elinks.x86_64 0:0.12-0.36.pre6.el7
Dependency Installed:
js.x86_64 1:1.8.5-19.el7
nss_compat_ossl.x86_64 0:0.9.6-8.el7
Complete!
8
Default installation of Apache web server use port 80 for HTTP traffic
and 443 for HTTPS traffic.
If Firewall is on Http and Httpd services should be added to firewall
with port tcp/443 for https and port tcp/80 for http
9
We need to set context of any newly created file or directory for the
web server user to be able to access it.
There are multiple commands for managing the SELinux context for
files, such as chcon, semanage fcontext, and restorecon
Run the chcon -t type file-name command to change the file type, where
type is a type, such as httpd_sys_content_t, and file-name is a file
or directory name.
Run the chcon -R -t type directory-name command to change the type of
the directory and its contents, where type is a type, such as
httpd_sys_content_t, and directory-name is a directory name.
We need to set context of any newly created file or directory for the
web server user to be able to access it.
Verify that all the context fields have been changed correctly
#ls -Z /var/www/html
10
httpd_dontaudit_search_dirs --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_graceful_shutdown --> on
httpd_manage_ipa --> off
httpd_mod_auth_ntlm_winbind --> off
httpd_mod_auth_pam --> off
httpd_read_user_content --> off
Booleans Descriptions
httpd_builtin_scripting Used to provide permission for php content
httpd_dbus_avahi Supports access from HTTP services
httpd_enable_cgi Allows HTTP services to execute GCI scripts
httpd_tty_comm Enables communication with controlling
terminals
Where :
Server IP :192.168.56.101
Client IP : 192.168.56.102
11
1 .Edit the /etc/httpd/conf/httpd.conf configuration file and customize the file
[root@server ]# vi /etc/httpd/conf/httpd.conf
Listen 80
ServerName www.agoutam.com:80
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
12
[root@server html]# systemctl enable httpd
Created symlink from
/etc/systemd/system/multi-user.target.wants/httpd.service to
/usr/lib/systemd/system/httpd.service.
13
Configuring Apache Webserver for Website using User-Defined Directory
Edit and Configure httpd.conf file for User Defined Apache Web Server
Directory
Listen 80
ServerName www.agoutam.com:80
#DocumentRoot "/var/www/html"
DocumentRoot "/web"
#
# Relax access to content within /var/www.
#
<Directory "/var/www/html">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
14
[root@server ]# cd /web
[root@server web]# vi index.html
[root@server web]# cat index.html
This is for demo Changing Root Directory to /web/agoutam for site
www.agoutam.com
15
To configure Virtual Hosts configuration for Apache web server
Virtual host feature of Apache allows you to define multiple web sites on single IP
address. For Virtual hosts configuration following options are required
Edit and Configure httpd.conf file and make entry for Virtual Host
Configuration :
<VirtualHost 192.168.56.101>
DocumentRoot /web
ServerName server.agoutam.com
ServerAdmin [email protected]
ErrorLog "logs/site_error.log"
CustomLog "logs/site_access.log" combines
</VirtualHost>
16
Deploying a Basic CGI-Application in Apache Web Server using
default CGI Directory /var/www/cgi-bin
http://www.agoutam.com/cgi-bin/cgidemo.pl
17
</Directory>
[root@server cgi-bin]#elinks
http://www.agoutam.com/cgi-bin/cgidemo.pl
18
To Set up SElinux configuration for the /webapp directory:
[root@server ]# vi /etc/httpd/conf/httpd.conf
19
To view CGI-Application using user-defined cgi directory
To View main configuration file for SSL and HTTPS web service
configuration,
20
string is too long, it needs to be less than 2 bytes long
Country Name (2 letter code) [XX]:IN
State or Province Name (full name) []:RANCHI
Locality Name (eg, city) [Default City]:RANCHI
Organization Name (eg, company) [Default Company Ltd]:AGOUTAM
Organizational Unit Name (eg, section) []:ABHISHEK
Common Name (eg, your name or your server's hostname)
[]:www.agoutam.com
Email Address []:[email protected]
[root@server conf.d]#
21
To view private key www.agoutam.com.key
To edit and Configure ssl.conf file for HTTPS service for web service
ServerName www.agoutam.com:443
DocumentRoot "/var/www/html"
Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate. If
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. A new
# certificate can be generated using the genkey(1) command.
22
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateFile /etc/pki/tls/certs/www.agoutam.com.crt
23
Certificate chain
0
s:/C=IN/ST=RANCHI/L=RANCHI/O=AGOUTAM/OU=ABHISHEK/CN=www.agoutam.com/
[email protected]
i:/C=IN/ST=RANCHI/L=RANCHI/O=AGOUTAM/OU=ABHISHEK/CN=www.agoutam.com/
[email protected]
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIEAzCCAuugAwIBAgIJANIhSQKDh9pBMA0GCSqGSIb3DQEBCwUAMIGXMQswCQYD
VQQGEwJJTjEPMA0GA1UECAwGUkFOQ0hJMQ8wDQYDVQQHDAZSQU5DSEkxEDAOBgNV
BAoMB0FHT1VUQU0xETAPBgNVBAsMCEFCSElTSEVLMRgwFgYDVQQDDA93d3cuYWdv
dXRhbS5jb20xJzAlBgkqhkiG9w0BCQEWGGFiaGlzaGVrdml0bWNhQHlhaG9vLmNv
BQADggEBAI+LIUWVKLxwQH7EkGivRZ4UfPIblFV7vQzLWaLvfdS0jXYImpu+stsz
MM+h9CAVRflXSBe1CIMeWRJFE8jciLge3yMmSeZbeWaYM5hZUNhOb7Hik81qrySM
tMVvYtOj0ufJ9LrU/U8ntvQFL6INkoSn1dtugZXhDaqHyYZHOyNLXAbxYn0E9co/
KaMyT+XFJjXgEhn7Yf4mZ5YG0GIGUCDxwi5Gfj+oEHFW0TjaLxiO3nBw+Yvofau4
h3sE2lj6tUtFzKs5KBpr89iP2BX2u1veU7x7cuOfSUY7Pp1C1e2LWshjxYqSj4cB
ft2P2iq9lLY4pGNwbspWzfEzW0PtEYg=
-----END CERTIFICATE-----
subject=/C=IN/ST=RANCHI/L=RANCHI/O=AGOUTAM/OU=ABHISHEK/
CN=www.agoutam.com/[email protected]
issuer=/C=IN/ST=RANCHI/L=RANCHI/O=AGOUTAM/OU=ABHISHEK/
CN=www.agoutam.com/[email protected]
---
No client certificate CA names sent
Peer signing digest: SHA512
Server Temp Key: ECDH, P-256, 256 bits
---
SSL handshake has read 1722 bytes and written 424 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
---
read:errno=0
[root@server conf.d]#
24
To Open configure website www.agoutam.com using secure Socket
Connection
25
After Allowing Security exception web Page could be accessed
To edit and Configure httpd.conf file for User private Directory for
web-Service
ServerName www.agoutam.com:80
DocumentRoot "/var/www/html"
<Directory "/var/www/html/privdir">
AllowOverride None
Options none
Require all granted
</Directory>
26
To Reload and Restart Apache web Service
User-Based Security
User based authentication provides a way to allow only certain users
to access web server.
Options Description
AuthType Defines the authentication method
AuthName Comment for the users
AuthUserFile File used to define username and password
AuthGroupFile File used to define groups
Require Specifies the users or groups that can log in
27
[root@server privdir]# vi /etc/httpd/conf/httpd.conf
Listen 80
ServerName www.agoutam.com:80
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory "/var/www/html/privdir">
AllowOverride None
Options none
Require all granted
<Directory>
<Directory "/var/www/html/privdir">
AuthType basic
AuthName "Password protected Area"
Authuserfile /etc/httpd/conf/passwd
Require user agoutam
</Directory>
28
To provide user and Group ownership to Apache web services to database
file passwd
29
root@server ]# mkdir /var/www/html/privdir/
Suppose that privdir folder contains the salary sheet of employees and
we want to allow only grp1 group to access it.
Create a .htaccess file in the privdir folder and add group user to
file so only group user can access the file.
[root@server ]# vi /etc/httpd/conf/httpd.conf
Listen 80
ServerName www.agoutam.com:80
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory "/var/www/html/privdir">
AllowOverride authconfig
Options none
Require all granted
<Directory>
30
[root@server privdir]# htpasswd -mc /etc/httpd/conf/userpasswd
grpuser1
New password:
Re-type new password:
Adding password for user grpuser1
[root@server privdir]# htpasswd -mc /etc/httpd/conf/userpasswd
grpuser2
New password:
Re-type new password:
Adding password for user grpuser2
[root@server privdir]#
[root@server privdir]# htpasswd -m /etc/httpd/conf/userpasswd
grpuser3
New password:
Re-type new password:
Adding password for user grpuser3
[root@server privdir]#
Create rhel7groupfile, this file will hold entry for users part of
group
31
[root@server privdir]# chcon -t httpd_sys_content_t
/var/www/html/privdir/.htaccess
# Either chcon or semanage command can be used
[root@server privdir]# semanage fcontext -a -t
httpd_sys_content_t /var/www/html/privdir/.htaccess
[root@server privdir]# restorecon -R -v
/var/www/html/privdir/.htaccess
[root@server privdir]#
32
Since grpuser3 is created but is not Added in group file
'rhel7groupfile'so user not able to access the folder privdir
content's
33