Apache deep dive

Apache Hypertext Transfer Protocol Server (httpd)

Apache:
Open Source cross-platform web server software
Services 57% of all active websites
Name comes from respect for apache Native American tribe(A PATCH SERVER)

http://httpd.apache.org/

https://en.wikipedia.org/wiki/List_of_Apache_modules

https://httpd.apache.org/docs/2.4/mod/

Background

Most of the functionality of the Apache web server is provided by modules. A module can be either:

static, meaning that it is built into the Apache executable at compile time (and is therefore always available).
shared, meaning that it is loaded at run time by a LoadModule directive within the Apache configuration file.

It is thus possible for a shared module to be installed on a machine, but not loaded by Apache and therefore not usable. This is one of the more common reasons for Apache failing to start or failing to behave as expected.

In short, the modules extend the Apache server. An administrator can easily configure Apache by adding and removing the modules according to required needs. Apache comes with a set or pre-installed modules.

[root@ansible ~]# yum install httpd httpd-manual 

[root@ansible ~]# service httpd restart

http://192.168.183.128/manual/

[root@ansible ~]# rpm -qa httpd
httpd-2.4.6-45.el7.centos.4.x86_64

[root@ansible ~]# grep LoadModule /etc/httpd/conf/httpd.conf
# have to place corresponding `LoadModule’ lines at this location so the
# LoadModule foo_module modules/mod_foo.so

Commonly used Apache modules

The below list shows few commonly used Apache modules.
1) Mod_security
2) Mod_rewrite
3) Mod_deflate
4) Mod_cache
5) Mod_proxy
6) Mod_ssl

Find list of compiled modules in Apache
[root@ansible ~]# httpd -l
Compiled in modules:
core.c
mod_so.c
http_core.c

Find list of loaded modules in Apache
[root@ansible ~]# httpd -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
access_compat_module (shared)
actions_module (shared)
alias_module (shared)
allowmethods_module (shared)
auth_basic_module (shared)
auth_digest_module (shared)
authn_anon_module (shared)
authn_core_module (shared)
authn_dbd_module (shared)
authn_dbm_module (shared)
authn_file_module (shared)
authn_socache_module (shared)
authz_core_module (shared)
authz_dbd_module (shared)
authz_dbm_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_owner_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cache_module (shared)
cache_disk_module (shared)
data_module (shared)
dbd_module (shared)
deflate_module (shared)
dir_module (shared)
dumpio_module (shared)
echo_module (shared)
env_module (shared)
expires_module (shared)
ext_filter_module (shared)
filter_module (shared)
headers_module (shared)
include_module (shared)
info_module (shared)
log_config_module (shared)
logio_module (shared)
mime_magic_module (shared)
mime_module (shared)
negotiation_module (shared)
remoteip_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
slotmem_plain_module (shared)
slotmem_shm_module (shared)
socache_dbm_module (shared)
socache_memcache_module (shared)
socache_shmcb_module (shared)
status_module (shared)
substitute_module (shared)
suexec_module (shared)
unique_id_module (shared)
unixd_module (shared)
userdir_module (shared)
version_module (shared)
vhost_alias_module (shared)
dav_module (shared)
dav_fs_module (shared)
dav_lock_module (shared)
lua_module (shared)
mpm_prefork_module (shared)
proxy_module (shared)
lbmethod_bybusyness_module (shared)
lbmethod_byrequests_module (shared)
lbmethod_bytraffic_module (shared)
lbmethod_heartbeat_module (shared)
proxy_ajp_module (shared)
proxy_balancer_module (shared)
proxy_connect_module (shared)
proxy_express_module (shared)
proxy_fcgi_module (shared)
proxy_fdpass_module (shared)
proxy_ftp_module (shared)
proxy_http_module (shared)
proxy_scgi_module (shared)
proxy_wstunnel_module (shared)
systemd_module (shared)
cgi_module (shared)
php5_module (shared)

[root@ansible ~]# httpd -M |wc -l
84

[root@ansible ~]# ls -l /usr/lib64/httpd/modules/ |wc -l
102

How to add new module ex: mod_ssl

[root@ansible ~]# yum install mod_ssl -y

[root@ansible ~]# httpd -M |wc -l
85

[root@ansible ~]# httpd -M |grep ssl
ssl_module (shared)

[root@ansible ~]# ls -l /usr/lib64/httpd/modules/ |grep -i ssl
-rwxr-xr-x 1 root root 219464 Apr 13 02:34 mod_ssl.so

[root@ansible ~]# ls -l /usr/lib64/httpd/modules/ |wc -l
103

####################################
[root@ansible ~]# cat /etc/httpd/conf/httpd.conf |wc -l
353
[root@ansible ~]# grep “#” /etc/httpd/conf/httpd.conf |wc -l
259

[root@ansible ~]# grep -v “#” /etc/httpd/conf/httpd.conf
ServerRoot “/etc/httpd”
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
AllowOverride none
Require all denied

DocumentRoot “/var/www/html”

<Directory “/var/www”>
AllowOverride None
Require all granted

<Directory “/var/www/html”>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
DirectoryIndex index.html

<Files “.ht*”>
Require all denied

ErrorLog “logs/error_log”
LogLevel warn

LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”” combined
LogFormat “%h %l %u %t \”%r\” %>s %b” common

LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\” %I %O” combinedio

CustomLog “logs/access_log” combined
ScriptAlias /cgi-bin/ “/var/www/cgi-bin/”

<Directory “/var/www/cgi-bin”>
AllowOverride None
Options None
Require all granted
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

AddDefaultCharset UTF-8

MIMEMagicFile conf/magic

EnableSendfile on
IncludeOptional conf.d/*.conf

apache1

 What is a module in Apache?
In computing, Apache, an open-source HTTP server, comprises a small core for HTTP request/response processing and for Multi-Processing Modules (MPM) which dispatches data processing to threads and/or processes. Many additional modules (or “mods” ) are available to extend the core functionality for special purposes.

What is a directive in Apache?
Apache directives are a set of rules which define how your server should run, number of clients that can access your server, etc. you can change them by editing the httpd.conf and related files to meet your requirements. shareimprove this answer. ex:Listen

Loading Modules
The default config file loads a large number of modules

LoadModule ldap_module modules/mod_ldap.so
LoadModule status_module modules/mod_status.so
LoadModule proxy_module modules/mod_proxy.so

Defining Multi-Process Settings
To improve response times, apache manages a pool of “spare” server processes

These numbers control the size of the pool:
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256

Containers
Container directives use XML-style opening / closing tags
Restrict the scope of the directives they contain

<Directory “/var/www/cgi-bin”>
AllowOverride None
Options None
within the specified
Order allow,deny
Allow from all

Other containers include <Location> and <VirtualHost>

 

Leave a comment