Ceci est une ancienne révision du document !
Table des matières
APF101 - Gestion de Base du Serveur Web Apache 2.4
Présentation d'Apache
Un serveur web est une machine doté d'un logiciel serveur qui attend des requêtes de la part de machines clientes afin de leur livrer de documents de types différents.
En 1994 le développement du serveur web le plus connue à l'époque, le démon HTTP, a été arrêté suite au départ de la NCSA de son principal développeur, Rob McCool.
Au début de l'année 1995, un groupe de webmestres indépendants s'est mis en place sous la direction de Brian Behlendorf et Cliff Skolnick pour reprendre le travail sur ce démon. Ce projet a pris le nom Apache. En même temps la NCSA a repris son propre travail de développement sur son démon HTTP. L'arrivée dans le groupe Apache de deux personnes de la NCSA en tant que membres honoraires, Brandon Long et Beth Frank a permis la mise en commun des connaissances des deux groupes.
Le projet Apache est un projet de développement d'un serveur web libre pour les plateformes Unix et Windows™. La première version officielle, la 0.6.2 est sortie en avril 1995.
La Fondation Apache, créée en 1999 par l'équipe Apache, gère aujourd'hui non seulement le projet Apache mais aussi un grand nombre d'autres projets. La liste des projets de la Fondation peut être trouvée ici.
Apache est modulaire. Certains modules fondamentaux conditionnent comment Apache traite la question du multitraitement. Les modules multitraitements - MPM - Multi-Processing Modules - sont différents selon le système d'exploitation utilisé et la charge attendue.
- mpm-winnt - module propre à Windows™ qui utilise son support réseau natif,
- mpm_netware - un serveur web basé exclusivement sur les threads et optimisé pour Novell NetWare™,
- mpmt_os2 - un serveur hybride multi-processus, multi-thread pour OS/2,
- prefork - module propre à Unix et Linux qui implémente un serveur mono-tâche à duplication,
- worker - module propre à Unix et Linux qui implémente un serveur hybride multi-tâche et multitraitement,
- event - module propre à Unix et Linux conçu pour permettre le traitement d'un nombre accru de requêtes simultanées en déléguant certaines tâches aux threads d'écoute, libérant par là-même les threads de travail et leur permettant de traiter les nouvelles requêtes.
Ces modules sont compilés statiquement au binaire Apache et sont mutuellement exclusifs.
Contenu de ce Cours
Dans ce cours, vous allez apprendre par la pratique :
- LAB #1 - Gestion de serveurs virtuels
- LAB #2 - Gestion des pages personnelles avec mod_userdir
Préparation
Désactivez le mode enforcing de SELINUX afin de pouvoir librement travailler avec Apache :
[root@centos7 ~]# setenforce permissive [root@centos7 ~]# getenforce Permissive [root@centos7 ~]# vi /etc/sysconfig/selinux [root@centos7 ~]# cat /etc/sysconfig/selinux # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=permissive # SELINUXTYPE= can take one of three two values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
Afin d'éviter les problèmes liés au pare-feu arrêtez le service firewalld :
[root@centos7 ~]# systemctl stop firewalld [root@centos7 ~]# systemctl disable firewalld [root@centos7 ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1) Aug 21 16:23:02 centos7.i2tch.loc systemd[1]: Starting firewalld - dynamic firewall daemon... Aug 21 16:23:07 centos7.i2tch.loc systemd[1]: Started firewalld - dynamic firewall daemon. Aug 21 16:29:49 centos7.i2tch.loc systemd[1]: Stopping firewalld - dynamic firewall daemon... Aug 21 16:29:49 centos7.i2tch.loc systemd[1]: Stopped firewalld - dynamic firewall daemon.
Installation à partir des dépôts
Sous RHEL / CentOS 7, Apache n'est pas installé par défaut. Utilisez donc yum pour l'installer :
[root@centos7 ~]# rpm -qa | grep httpd [root@centos7 ~]# [root@centos7 ~]# yum install httpd
La version d'Apache est la 2.4.6 :
[root@centos7 ~]# rpm -qa | grep httpd httpd-2.4.6-45.el7.centos.4.x86_64 httpd-tools-2.4.6-45.el7.centos.4.x86_64
Configurez le service pour démarrer automatiquement :
[root@centos7 ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:httpd(8) man:apachectl(8) [root@centos7 ~]# systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Lancez votre service apache :
[root@centos7 ~]# systemctl start httpd [root@centos7 ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2017-08-22 11:19:18 CEST; 3s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 1293 (httpd) Status: "Processing requests..." CGroup: /system.slice/httpd.service ├─1293 /usr/sbin/httpd -DFOREGROUND ├─1296 /usr/sbin/httpd -DFOREGROUND ├─1297 /usr/sbin/httpd -DFOREGROUND ├─1298 /usr/sbin/httpd -DFOREGROUND ├─1299 /usr/sbin/httpd -DFOREGROUND └─1300 /usr/sbin/httpd -DFOREGROUND Aug 22 11:19:18 centos7.i2tch.loc systemd[1]: Starting The Apache HTTP Server... Aug 22 11:19:18 centos7.i2tch.loc systemd[1]: Started The Apache HTTP Server.
Configuration sous RHEL / CentOS 7
/etc/httpd/conf/httpd.conf
Sous Red Hat / CentOS 7 le fichier de configuration principal d'apache est /etc/httpd/conf/httpd.conf. Cette configuration est complémentée par les directives se trouvant dans les fichiers contenus dans les répertoires /etc/httpd/conf.modules.d/ et /etc/httpd/conf.d/ :
[root@centos7 ~]# ls -lR /etc/httpd /etc/httpd: total 4 drwxr-xr-x. 2 root root 35 Aug 22 11:17 conf drwxr-xr-x. 2 root root 78 Aug 22 11:17 conf.d drwxr-xr-x. 2 root root 4096 Aug 22 11:17 conf.modules.d lrwxrwxrwx. 1 root root 19 Aug 22 11:17 logs -> ../../var/log/httpd lrwxrwxrwx. 1 root root 29 Aug 22 11:17 modules -> ../../usr/lib64/httpd/modules lrwxrwxrwx. 1 root root 10 Aug 22 11:17 run -> /run/httpd /etc/httpd/conf: total 28 -rw-r--r--. 1 root root 11753 Apr 12 15:50 httpd.conf -rw-r--r--. 1 root root 13077 Apr 12 23:04 magic /etc/httpd/conf.d: total 16 -rw-r--r--. 1 root root 2926 Apr 12 23:03 autoindex.conf -rw-r--r--. 1 root root 366 Apr 12 23:04 README -rw-r--r--. 1 root root 1252 Apr 12 15:50 userdir.conf -rw-r--r--. 1 root root 824 Apr 12 15:50 welcome.conf /etc/httpd/conf.modules.d: total 28 -rw-r--r--. 1 root root 3739 Apr 12 15:50 00-base.conf -rw-r--r--. 1 root root 139 Apr 12 15:50 00-dav.conf -rw-r--r--. 1 root root 41 Apr 12 15:50 00-lua.conf -rw-r--r--. 1 root root 742 Apr 12 15:50 00-mpm.conf -rw-r--r--. 1 root root 957 Apr 12 15:50 00-proxy.conf -rw-r--r--. 1 root root 88 Apr 12 15:50 00-systemd.conf -rw-r--r--. 1 root root 451 Apr 12 15:50 01-cgi.conf
Les directives actives du fichier /etc/httpd/conf/httpd.conf sont les suivantes :
[root@centos7 ~]# egrep -v '^(#|$)' /etc/httpd/conf/httpd.conf > /tmp/httpd.conf [root@centos7 ~]# cat /tmp/httpd.conf ServerRoot "/etc/httpd" Listen 80 Include conf.modules.d/*.conf User apache Group apache ServerAdmin root@localhost <Directory /> AllowOverride none Require all denied </Directory> DocumentRoot "/var/www/html" <Directory "/var/www"> AllowOverride None Require all granted </Directory> <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> <IfModule dir_module> DirectoryIndex index.html </IfModule> <Files ".ht*"> Require all denied </Files> ErrorLog "logs/error_log" LogLevel warn <IfModule log_config_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule> CustomLog "logs/access_log" combined </IfModule> <IfModule alias_module> ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" </IfModule> <Directory "/var/www/cgi-bin"> AllowOverride None Options None Require all granted </Directory> <IfModule mime_module> TypesConfig /etc/mime.types AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType text/html .shtml AddOutputFilter INCLUDES .shtml </IfModule> AddDefaultCharset UTF-8 <IfModule mime_magic_module> MIMEMagicFile conf/magic </IfModule> EnableSendfile on IncludeOptional conf.d/*.conf
Les Directives du fichier /etc/httpd/conf/httpd.conf
ServerRoot
Cette directive indique la racine de la configuration d'apache.
ServerRoot "/etc/httpd"
Listen
Cette directive indique le port écouté par apache.
Listen 80
Include
Cette directive indique que les fichiers de configuration inclus dans le répertoire conf.modules.d/*.conf doivent être inclus dans httpd.conf :
Include conf.modules.d/*.conf
User et Group
Cette directive indique l'UID et le GID de l'utilisateur qui exécute le service apache :
User apache Group apache
ServerAdmin
Cette directive indique l'adresse email de l'administrateur du serveur apache :
ServerAdmin root@localhost
<Directory />
Cette directive permet de regrouper d'autres directives s'appliquant à un répertoire précis - dans ce cas la racine du site :
<Directory />
Require all
Cette directive autorise ou interdit l'accès. Dans ce cas l'interdiction concerne tout le monde.
Require all denied
AllowOverride
Cette directive stipule comment Apache doit utiliser les directives situées dans un éventuel fichier .htaccess La valeur none désactive l'utilisation du fichier .htaccess dans le répertoire.
AllowOverride None
</Directory>
Cette directive ferme le bloc Directory.
</Directory>
DocumentRoot
Cette directive indique l'emplacement par défaut des pages web à servir :
DocumentRoot "/var/www/html"
<Directory "/var/www">
Cette directive définit des règles pour le répertoire /var/www/ :
<Directory "/var/www">
AllowOverride
Cette directive stipule comment Apache doit utiliser les directives situées dans un éventuel fichier .htaccess La valeur none désactive l'utilisation du fichier .htaccess dans le répertoire /var/www/.
AllowOverride None
Require all
Cette directive autorise ou interdit l'accès. Dans ce cas l'autorisation concerne tout le monde.
Require all granted
</Directory>
Cette directive ferme le bloc Directory.
</Directory>
<Directory "/var/www/html">
Cette directive définit des règles pour le répertoire htdocs :
<Directory "/var/www/html">
Indexes
La directive Options active (+) ou désactive (-) des fonctions spécifiques. Dans ce cas Indexes autorise au serveur apache de générer une liste du contenu du répertoire dans le cas ou le fichier index ne peut pas être trouve tandis que FollowSymLinks permet à apache de suivre les liens symboliques.
Options Indexes FollowSymLinks
AllowOverride
Cette directive stipule comment Apache doit utiliser les directives situées dans un éventuel fichier .htaccess La valeur none désactive l'utilisation du fichier .htaccess dans le répertoire /var/www/html.
AllowOverride None
Require all
Cette directive autorise ou interdit l'accès. Dans ce cas l'autorisation concerne tout le monde.
Require all granted
</Directory>
Cette directive ferme le bloc Directory.
</Directory>
IfModule
IfModule dir_module indique que le pavé ne sera interprété QUE dans le cas ou le module dir_module soit chargé.
<IfModule dir_module>
DirectoryIndex
La directive DirectoryIndex stipule la liste des pages servies par défaut.
DirectoryIndex index.html
</IfModule>
Cette directive ferme le bloc IfModule
</IfModule>
Files
La directive Files recherche des fichiers qui correspondent a l'expression régulière passée en argument.
<Files ".ht*"> Require all denied </Files>
ErrorLog
Cette directive indique l'emplacement du journal d'erreurs.
ErrorLog "logs/error_log"
LogLevel
Cette directive indique le niveau de journalisation au format syslog: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
IfModule
IfModule log_config_module indique que le pavé ne sera interprété QUE dans le cas ou le module log_config_module soit chargé.
<IfModule log_config_module>
LogFormat
La directive LogFormat définit un format de journal et l'associe avec un nom. Cette directive prend la forme :
LogFormat format|nom
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
L'argument format est une chaîne qui peut contenir des caractères littéraux, des caractères de contrôle (par exemple \n pour une nouvelle ligne et \t pour une tabulation). Les “ littérales et les \ doivent être précédés par un caractère d'échappement.
Les significations des chaînes de formatage sont les suivantes :
Chaîne | Description |
---|---|
%b | La taille de la réponse sans les entêtes HTTP. Le caractère - indique 0 |
%h | L'hôte distant |
%l | Le nom du compte de l'utilisateur distant |
%r | La première ligne de la requête |
%>s | Le statut de la dernière requête |
%t | L'heure de la réception de la requête par le serveur |
%u | Le nom du compte de l'utilisateur distant |
%U | l'URL demandé |
%{Referer}i | Le contenu de Referer dans l'entête HTTP de la requête. |
%{User-agent}i | Le contenu de User-agent dans l'entête HTTP de la requête. |
%I | Octets reçus, en-têtes et corps de requête inclus ; ne peut pas être nul. |
%O | Octets envoyés, en-têtes inclus ; ne peut pas être nul. |
CustomLog
La directive CustomLog est utilisée pour écrire les journaux. Cette directive prend la forme :
CustomLog fichier|tube format
CustomLog "logs/access_log" combined
Le premier argument est donc soit :
- un fichier - un chemin complet, relatif à ServerRoot, vers un fichier journal, soit
- un tube - le caractère | suivi par un chemin indiquant le programme qui recevra l'information du journal sur son entrée standard. Le programme concerné est exécuté avec l'UID de l'utilisateur qui a lancé Apache. Si cette utilisateur est root, le programme s'exécute sous root !
Le deuxième argument peut être soit :
- Un format - un format de journal si celui-ci n'a pas été définit par une directive LogFormat, soit
- Un nom - un nom définit par une directive LogFormat
Consultez votre journal d'accès :
[root@centos7 ~]# cat /var/log/httpd/access_log 127.0.0.1 - - [22/Aug/2017:11:31:25 +0200] "GET /" 403 4897 "-" "-" 127.0.0.1 - - [22/Aug/2017:15:46:32 +0200] "GET / HTTP/1.1" 403 4897 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" 127.0.0.1 - - [22/Aug/2017:15:46:32 +0200] "GET /noindex/css/bootstrap.min.css HTTP/1.1" 200 19341 "http://localhost/" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" 127.0.0.1 - - [22/Aug/2017:15:46:32 +0200] "GET /noindex/css/open-sans.css HTTP/1.1" 200 5081 "http://localhost/" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" 127.0.0.1 - - [22/Aug/2017:15:46:32 +0200] "GET /images/apache_pb.gif HTTP/1.1" 200 2326 "http://localhost/" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" 127.0.0.1 - - [22/Aug/2017:15:46:32 +0200] "GET /images/poweredby.png HTTP/1.1" 200 3956 "http://localhost/" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" 127.0.0.1 - - [22/Aug/2017:15:46:32 +0200] "GET /noindex/css/fonts/Light/OpenSans-Light.woff HTTP/1.1" 404 241 "http://localhost/noindex/css/open-sans.css" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" 127.0.0.1 - - [22/Aug/2017:15:46:32 +0200] "GET /noindex/css/fonts/Bold/OpenSans-Bold.woff HTTP/1.1" 404 239 "http://localhost/noindex/css/open-sans.css" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" 127.0.0.1 - - [22/Aug/2017:15:46:32 +0200] "GET /noindex/css/fonts/Light/OpenSans-Light.ttf HTTP/1.1" 404 240 "http://localhost/noindex/css/open-sans.css" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" 127.0.0.1 - - [22/Aug/2017:15:46:32 +0200] "GET /noindex/css/fonts/Bold/OpenSans-Bold.ttf HTTP/1.1" 404 238 "http://localhost/noindex/css/open-sans.css" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" 127.0.0.1 - - [22/Aug/2017:15:46:32 +0200] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" 127.0.0.1 - - [22/Aug/2017:15:46:32 +0200] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0"
où :
Chaîne | Valeur |
---|---|
%h | 127.0.0.1 |
%l | - |
%u | - |
%t | [22/Aug/2017:15:46:32 +0200] |
%r | “GET /favicon.ico HTTP/1.1” |
%>s | 404 |
%b | 209 |
%{Referer}i | - |
%{User-agent}i | “Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0” |
</IfModule>
Cette directive ferme le bloc IfModule
</IfModule>
ScriptAlias
La directive ScriptAlias sert ici à créer un lien pour le répertoire cgi-bin dans le cas où le module alias_module soit chargé :
<IfModule alias_module> ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" </IfModule> <Directory "/var/www/cgi-bin"> AllowOverride None Options None Require all granted </Directory>
TypesConfig
Cette directive indique l'emplacement du fichier mime.types qui contient les correspondances mime des fichiers à afficher dans le cas où le module mime_module soit chargé :
<IfModule mime_module> TypesConfig /etc/mime.types ... </IfModule>
AddType
Cette directive stipule un contenu MIME-type pour une extension de fichier donnée dans le cas où le module mime_module soit chargé :
<IfModule mime_module> ... AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType text/html .shtml ... </IfModule>
AddoutputFilter
La directive AddOutputFilter fait correspondre une extension de fichier avec un filtre. Les réponses du serveur aux requêtes des clients sont ensuite envoyées vers le filtre avant d'être retournées aux clients :
<IfModule mime_module> ... AddOutputFilter INCLUDES .shtml </IfModule>
AddDefaultCharset
Cette directive spécifie un jeu de caractères par défaut de UTF-8 pour tout document du type text/plain ou text/html. L'utilisation de cette option écrase tout autre spécification basée sur le MIME-Type.
AddDefaultCharset UTF-8
MIMEMagicFile
Cette directive stipule le fichier magic. Le fichier magic est utilise pour déterminer le type mime d'un fichier.
<IfModule mime_magic_module> MIMEMagicFile conf/magic </IfModule>
EnableSendfile
Cette directive définit si le programme httpd peut utiliser le support sendfile du noyau pour transmettre le contenu des fichiers aux clients. Par défaut, lorsque le traitement d'une requête ne requiert pas l'accès aux données contenues dans un fichier – par exemple, pour la transmission d'un fichier statique – Apache httpd utilise sendfile pour transmettre le contenu du fichier sans même lire ce dernier, si le système d'exploitation le permet :
EnableSendfile on
IncludeOptional
Cette directive permet d'inclure des fichiers dans les fichiers de configuration du serveur. Elle fonctionne de manière identique à la directive Include, à l'exception du fait que si l'expression avec caractères génériques wilcard ne correspond à aucun fichier ou répertoire, elle sera ignorée silencieusement au lieu de causer une erreur :
IncludeOptional conf.d/*.conf
/etc/httpd/conf.d/autoindex.conf
Les directives actives du fichier /etc/httpd/conf.d/autoindex.conf sont les suivantes :
[root@centos7 ~]# egrep -v '^(#|$)' /etc/httpd/conf.d/autoindex.conf > /tmp/autoindex.conf [root@centos7 ~]# cat /tmp/autoindex.conf IndexOptions FancyIndexing HTMLTable VersionSort Alias /icons/ "/usr/share/httpd/icons/" <Directory "/usr/share/httpd/icons"> Options Indexes MultiViews FollowSymlinks AllowOverride None Require all granted </Directory> AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip AddIconByType (TXT,/icons/text.gif) text/* AddIconByType (IMG,/icons/image2.gif) image/* AddIconByType (SND,/icons/sound2.gif) audio/* AddIconByType (VID,/icons/movie.gif) video/* AddIcon /icons/binary.gif .bin .exe AddIcon /icons/binhex.gif .hqx AddIcon /icons/tar.gif .tar AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip AddIcon /icons/a.gif .ps .ai .eps AddIcon /icons/layout.gif .html .shtml .htm .pdf AddIcon /icons/text.gif .txt AddIcon /icons/c.gif .c AddIcon /icons/p.gif .pl .py AddIcon /icons/f.gif .for AddIcon /icons/dvi.gif .dvi AddIcon /icons/uuencoded.gif .uu AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl AddIcon /icons/tex.gif .tex AddIcon /icons/bomb.gif /core AddIcon /icons/bomb.gif */core.* AddIcon /icons/back.gif .. AddIcon /icons/hand.right.gif README AddIcon /icons/folder.gif ^^DIRECTORY^^ AddIcon /icons/blank.gif ^^BLANKICON^^ DefaultIcon /icons/unknown.gif ReadmeName README.html HeaderName HEADER.html IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
Les Directives du fichier /etc/httpd/conf.d/autoindex.conf
IndexOptions
mod_autoindex permet la génération automatique des listes du contenu d'un répertoire quand la page d'index n'est par présente. L'option de génération est activée par la directive Options +Indexes. La directive FancyIndexing produit des colonnes ayant des liens en tête. Ces liens peuvent être utilisés pour trier l'index. La directive VersionSort permet une liste naturelle de fichiers ayant des numéros de versions tels foo-1.8.2 et foo-1.8.2a :
IndexOptions FancyIndexing HTMLTable VersionSort
Alias
La directive Alias sert ici à créer un lien pour le répertoire icons :
Alias /icons/ "/usr/share/httpd/icons/"
<Directory "/usr/share/httpd/icons">
Cette section définit les règles pour le répertoire /var/www/icons :
<Directory "/usr/share/httpd/icons"> Options Indexes MultiViews FollowSymlinks AllowOverride None Require all granted </Directory>
AddIconByEncoding
Cette directive indique l'icône à afficher avec FancyIndexing en stipulant un chemin complet pour le type MIME-type indiqué. Le format est (alttext,url) où alttext indique le texte à afficher pour les navigateurs texte :
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
AddIconByType
Cette directive indique l'icône à afficher avec FancyIndexing en stipulant le type MIME-type indiqué. Le format est (alttext,MIME-type) où alttext indique le texte à afficher pour les navigateurs texte :
AddIconByType (TXT,/icons/text.gif) text/* AddIconByType (IMG,/icons/image2.gif) image/* AddIconByType (SND,/icons/sound2.gif) audio/* AddIconByType (VID,/icons/movie.gif) video/*
AddIcon
Cette directive indique l'icône à afficher avec FancyIndexing en stipulant un nomou un extension. Le format est (alttext,nom/ext) où alttext indique le texte à afficher pour les navigateurs texte :
AddIcon /icons/binary.gif .bin .exe AddIcon /icons/binhex.gif .hqx AddIcon /icons/tar.gif .tar AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip AddIcon /icons/a.gif .ps .ai .eps AddIcon /icons/layout.gif .html .shtml .htm .pdf AddIcon /icons/text.gif .txt AddIcon /icons/c.gif .c AddIcon /icons/p.gif .pl .py AddIcon /icons/f.gif .for AddIcon /icons/dvi.gif .dvi AddIcon /icons/uuencoded.gif .uu AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl AddIcon /icons/tex.gif .tex AddIcon /icons/bomb.gif /core AddIcon /icons/bomb.gif */core.* AddIcon /icons/back.gif .. AddIcon /icons/hand.right.gif README AddIcon /icons/folder.gif ^^DIRECTORY^^ AddIcon /icons/blank.gif ^^BLANKICON^^
DefaultIcon
La directive DefaultIcon indique l'icône servie en absence d'un type de fichier connu :
DefaultIcon /icons/unknown.gif
ReadmeName
Cette directive indique le fichier qui sera ajouter à la fin de l'index. Si le nom du fichier est précédé par un /, Apache prend le chemin relatif à la directive DocumentRoot. Dans le cas contraire, Apache cherche le fichier dans le répertoire pour lequel l'index est généré :
ReadmeName README.html
HeaderName
Cette directive indique le fichier qui sera inséré en tête de l'index. Si le nom du fichier est précédé par un /, Apache prend le chemin relatif à la directive DocumentRoot. Dans le cas contraire, Apache cherche le fichier dans le répertoire pour lequel l'index est généré :
HeaderName HEADER.html
IndexIgnore
Cette directive stipule les types de fichiers à exclure de l'index :
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
/etc/httpd/conf.d/userdir.conf
Ce fichier configure la mise à disposition de pages personnelles pour chaque utilisateur ayant un compte sur le serveur Linux.
Les directives actives du fichier /etc/httpd/conf.d/userdir.conf sont les suivantes :
[root@centos7 ~]# egrep -v '^(#|$)' /etc/httpd/conf.d/userdir.conf > /tmp/userdir.conf [root@centos7 ~]# cat /tmp/userdir.conf <IfModule mod_userdir.c> UserDir disabled </IfModule> <Directory "/home/*/public_html"> AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS </Directory>
Les Directives du fichier /etc/httpd/conf.d/userdir.conf
<IfModule mod_userdir.c>
Cette directive vérifie si mod_userdir est active.
<IfModule mod_userdir.c>
UserDir
Le but de cette directive est d'interdire le support des répertoires des utilisateurs :
UserDir disable
/etc/httpd/conf.d/welcome.conf
Ce fichier configure l'affichage de la page par défaut du serveur Apache dans le cas où il n'existe pas de fichier index.html.
Les directives actives du fichier /etc/httpd/conf.d/welcome.conf sont les suivantes :
[root@centos7 ~]# egrep -v '^(#|$)' /etc/httpd/conf.d/welcome.conf > /tmp/welcome.conf [root@centos7 ~]# cat /tmp/welcome.conf <LocationMatch "^/+$"> Options -Indexes ErrorDocument 403 /.noindex.html </LocationMatch> <Directory /usr/share/httpd/noindex> AllowOverride None Require all granted </Directory> Alias /.noindex.html /usr/share/httpd/noindex/index.html Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
/etc/httpd/conf.modules.d/00-*.conf
Ces fichiers configurent le chargement des modules d'Apache.
Par exemple, les directives actives du fichier /etc/httpd/conf.modules.d/00-base.conf sont les suivantes :
[root@centos7 ~]# egrep -v '^(#|$)' /etc/httpd/conf.modules.d/00-base.conf > /tmp/base.conf [root@centos7 ~]# cat /tmp/base.conf LoadModule access_compat_module modules/mod_access_compat.so LoadModule actions_module modules/mod_actions.so LoadModule alias_module modules/mod_alias.so LoadModule allowmethods_module modules/mod_allowmethods.so LoadModule auth_basic_module modules/mod_auth_basic.so LoadModule auth_digest_module modules/mod_auth_digest.so LoadModule authn_anon_module modules/mod_authn_anon.so LoadModule authn_core_module modules/mod_authn_core.so LoadModule authn_dbd_module modules/mod_authn_dbd.so LoadModule authn_dbm_module modules/mod_authn_dbm.so LoadModule authn_file_module modules/mod_authn_file.so LoadModule authn_socache_module modules/mod_authn_socache.so LoadModule authz_core_module modules/mod_authz_core.so LoadModule authz_dbd_module modules/mod_authz_dbd.so LoadModule authz_dbm_module modules/mod_authz_dbm.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule authz_owner_module modules/mod_authz_owner.so LoadModule authz_user_module modules/mod_authz_user.so LoadModule autoindex_module modules/mod_autoindex.so LoadModule cache_module modules/mod_cache.so LoadModule cache_disk_module modules/mod_cache_disk.so LoadModule data_module modules/mod_data.so LoadModule dbd_module modules/mod_dbd.so LoadModule deflate_module modules/mod_deflate.so LoadModule dir_module modules/mod_dir.so LoadModule dumpio_module modules/mod_dumpio.so LoadModule echo_module modules/mod_echo.so LoadModule env_module modules/mod_env.so LoadModule expires_module modules/mod_expires.so LoadModule ext_filter_module modules/mod_ext_filter.so LoadModule filter_module modules/mod_filter.so LoadModule headers_module modules/mod_headers.so LoadModule include_module modules/mod_include.so LoadModule info_module modules/mod_info.so LoadModule log_config_module modules/mod_log_config.so LoadModule logio_module modules/mod_logio.so LoadModule mime_magic_module modules/mod_mime_magic.so LoadModule mime_module modules/mod_mime.so LoadModule negotiation_module modules/mod_negotiation.so LoadModule remoteip_module modules/mod_remoteip.so LoadModule reqtimeout_module modules/mod_reqtimeout.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule setenvif_module modules/mod_setenvif.so LoadModule slotmem_plain_module modules/mod_slotmem_plain.so LoadModule slotmem_shm_module modules/mod_slotmem_shm.so LoadModule socache_dbm_module modules/mod_socache_dbm.so LoadModule socache_memcache_module modules/mod_socache_memcache.so LoadModule socache_shmcb_module modules/mod_socache_shmcb.so LoadModule status_module modules/mod_status.so LoadModule substitute_module modules/mod_substitute.so LoadModule suexec_module modules/mod_suexec.so LoadModule unique_id_module modules/mod_unique_id.so LoadModule unixd_module modules/mod_unixd.so LoadModule userdir_module modules/mod_userdir.so LoadModule version_module modules/mod_version.so LoadModule vhost_alias_module modules/mod_vhost_alias.so
/etc/httpd/conf.d/local.conf
Afin de complémenter la configuration de base d'Apache, nous pouvons créer un fichier contenant nos directives dans le répertoire /etc/httpd/conf.d/. Creéz donc le fichier /etc/httpd/conf.d/local.conf :
[root@centos7 ~]# vi /etc/httpd/conf.d/local.conf [root@centos7 ~]# cat /etc/httpd/conf.d/local.conf ServerTokens OS Timeout 60 KeepAlive Off MaxKeepAliveRequests 100 KeepAliveTimeout 15 <IfModule prefork.c> StartServers 8 MinSpareServers 5 MaxSpareServers 20 ServerLimit 256 MaxClients 256 MaxRequestsPerChild 4000 </IfModule> UseCanonicalName Off AccessFileName .htaccess HostnameLookups Off ServerSignature On AddLanguage ca .ca AddLanguage cs .cz .cs AddLanguage da .dk AddLanguage de .de AddLanguage el .el AddLanguage en .en AddLanguage eo .eo AddLanguage es .es AddLanguage et .et AddLanguage fr .fr AddLanguage he .he AddLanguage hr .hr AddLanguage it .it AddLanguage ja .ja AddLanguage ko .ko AddLanguage ltz .ltz AddLanguage nl .nl AddLanguage nn .nn AddLanguage no .no AddLanguage pl .po AddLanguage pt .pt AddLanguage pt-BR .pt-br AddLanguage ru .ru AddLanguage sv .sv AddLanguage zh-CN .zh-cn AddLanguage zh-TW .zh-tw AddHandler type-map var LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW ForceLanguagePriority Prefer Fallback BrowserMatch "Mozilla/2" nokeepalive BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0 BrowserMatch "RealPlayer 4\.0" force-response-1.0 BrowserMatch "Java/1\.0" force-response-1.0 BrowserMatch "JDK/1\.0" force-response-1.0 BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully BrowserMatch "MS FrontPage" redirect-carefully BrowserMatch "^WebDrive" redirect-carefully BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully BrowserMatch "^gnome-vfs/1.0" redirect-carefully BrowserMatch "^XML Spy" redirect-carefully BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully ServerName www.i2tch.loc:80 ExtendedStatus On <Location /server-status> SetHandler server-status Require ip 127.0.0.1 </Location> <Location /server-info> SetHandler server-info Require ip 127.0.0.1 </Location>
Les Directives du fichier /etc/httpd/conf.d/local.conf
Dans ce fichier on trouve les directives suivantes :
ServerTokens
Cette directive indique le contenu de l'entête HTTP. La valeur peut être : Full | OS | Minor | Minimal | Major | Prod.
ServerTokens OS
Timeout
Cette directive indique le nombre de secondes entre une requête et le timeout :
Timeout 60
KeepAlive
Cette directive interdit plusieurs requêtes par connexion :
KeepAlive Off
MaxKeepAliveRequests
Cette directive fixe le nombre maximum de requêtes par connexion ( 0 = infinie ) :
MaxKeepAliveRequests 100
KeepAliveTimeout
Cette directive fixe le nombre de seconds d'attente pour recevoir la requête suivante du même client sur la même connexion :
KeepAliveTimeout 15
StartServers, MinSpareServers et MaxSpareServers
Ces directives contrôlent le nombre de processus serveur fils au lancement d'Apache, au minimum et au maximum. La valeur par défaut pour prefork de StartServers est de 5 :
StartServers 8 MinSpareServers 5 MaxSpareServers 20
ServerLimit
Pour le module prefork, cette directive définie la valeur maximale de la directive MaxRequestWorkers (anciennement MaxClients) pour la durée de vie du processus Apache :
ServerLimit 256
MaxRequestWorkers
Pour le module prefork, la directive MaxRequestWorkers indique le nombre maximal de processus fils qui seront lancés pour traiter les requêtes. Sa valeur par défaut est de 256 :
MaxRequestWorkers 256
MaxConnectionsPerChild
La directive MaxConnectionsPerChild (anciennement MaxRequestsPerChild) fixe la limite du nombre de requêtes traitées par un processus fils avant que celui-ci expire. Si la valeur de MaxRequestsPerChild est 0, le processus n'expirera jamais :
MaxConnectionsPerChild 4000
UseCanonicalName
Cette directive indique a apache comment construire les variables SERVER_NAME et SERVER_PORT. Quand la directive est On, Apache utilise la valeur de la directive ServerName. Quand la directive est Off, Apache utilise les valeurs fournies par le navigateur du client :
UseCanonicalName Off
AccessFileName
Cette directive indique le nom des fichiers de permissions a utiliser avec le fichier .htpasswd.
AccessFileName .htaccess
HostnameLookups
Cette directive autorise (On) ou désactive (Off) la résolution DNS pour la trace d'accès.
HostnameLookups Off
ServerSignature
Cette directive indique si la signature du serveur sera sur les pages d'erreurs: On | Off | EMail
ServerSignature On
AddLanguage
La directive AddLanguage stipule l'extension du fichier à pour le code langage indiqué :
AddLanguage ca .ca AddLanguage cs .cz .cs AddLanguage da .dk AddLanguage de .de AddLanguage el .el AddLanguage en .en AddLanguage eo .eo AddLanguage es .es AddLanguage et .et AddLanguage fr .fr AddLanguage he .he AddLanguage hr .hr AddLanguage it .it AddLanguage ja .ja AddLanguage ko .ko AddLanguage ltz .ltz AddLanguage nl .nl AddLanguage nn .nn AddLanguage no .no AddLanguage pl .po AddLanguage pt .pt AddLanguage pt-BR .pt-br AddLanguage ru .ru AddLanguage sv .sv AddLanguage zh-CN .zh-cn AddLanguage zh-TW .zh-tw
LanguagePriority
Le module mod_negotiation fournit la négociation de contenus et est inclus dans Apache par défaut. Il est ainsi possible d'utiliser les informations fournies par le navigateur (préférences de langues, jeu de caractères, encodage et types de médias). Apache a besoin de connaître des informations à propos de chacune des variantes. Ceci peut être fait de deux manières :
- Réaliser un fichier *.var, une Table de Types qui précise les fichiers définissant les variantes,
- Utiliser une recherche MultiViews.
Dans le cas de l'utilisation des fichiers *.var, Apache en est informé par l'utilisation de la directive AddHandler.
AddHandler type-map var
Pour plus d'informations concernant mod_negociation, veuillez consulter cette page
La directive LanguagePriority indique une liste de langues à utiliser par ordre de priorité de gauche à droite. Cette priorité joue dans le cas où Apache trouve deux ou plusieurs versions satisfaisantes du même document. En effet c'est la directive ForceLanguagePriority, utilisée avec la valeur Prefer qui indique à Apache d'utiliser le premier langue de la liste de priorité définit par LanguagePriority. La valeur Fallback indique à Apache que dans le cas où aucune version satisfaisante du document n'est trouvée, Apache doit utilisé la première version de la liste définit par LanguagePriority :
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW ForceLanguagePriority Prefer Fallback
mod_setenvif
mod_setenvif permet de définir des variables d'environnement.
Le variable downgrade-1.0 oblige Apache à traiter la requête comme du HTTP/1.0 même si elle a été construite sur une norme plus récente.
Le variable force-response-1.0, initialement implémenté pour résoudre un problème avec les serveurs mandataires d'AOL, oblige Apache à n'envoyer que des réponses en HTTP/1.0 aux clients.
Le variable nokeepalive désactive Keep-Alive, une extension à HTTP/1.0 qui permet d'envoyer de requêtes multiples sur la même connexion TCP.
Le variable redirect-carefully rend le serveur plus attentif quand il doit envoyer une redirection au client. Cette variable est habituellement utilisée quand un client a un problème connu pour gérer les redirections.
BrowserMatch "Mozilla/2" nokeepalive BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0 BrowserMatch "RealPlayer 4\.0" force-response-1.0 BrowserMatch "Java/1\.0" force-response-1.0 BrowserMatch "JDK/1\.0" force-response-1.0 BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully BrowserMatch "MS FrontPage" redirect-carefully BrowserMatch "^WebDrive" redirect-carefully BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully BrowserMatch "^gnome-vfs/1.0" redirect-carefully BrowserMatch "^XML Spy" redirect-carefully BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully
ServerName
Cette directive indique le nom du serveur. Décommentez cette directive et modifiez-la ainsi :
ServerName www.i2tch.loc:80
mod-status
Ce module permet à l'administrateur d'Apache de visualiser des informations sur la charge du serveur (requêtes, processus etc.). La directive ExtendedStatus doit être On pour obtenir le maximum de renseignements. Pour activer l'utilisation de ce module, ajoutez les lignes suivantes :
ExtendedStatus On <Location /server-status> SetHandler server-status Require ip 127.0.0.1 </Location>
mod_info
Ce module permet d'obtenir une vue d'ensemble de la configuration courante du serveur dont la liste des modules installés et des directives des fichiers de configuration du serveur. Pour activer ce module ajoutez les lignes suivantes :
<Location /server-info> SetHandler server-info Require ip 127.0.0.1 </Location>
Application de la Configuration
Editez le fichier /etc/hosts et ajoutez la ligne suivante:
10.0.2.15 i2tch.loc 10.0.2.15 www.i2tch.loc
Re-démarrez le serveur httpd :
[root@centos7 ~]# systemctl restart httpd [root@centos7 ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2017-08-24 10:19:38 CEST; 9s ago Docs: man:httpd(8) man:apachectl(8) Process: 17996 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS) Process: 21235 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS) Main PID: 18013 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─18013 /usr/sbin/httpd -DFOREGROUND ├─18014 /usr/sbin/httpd -DFOREGROUND ├─18015 /usr/sbin/httpd -DFOREGROUND ├─18016 /usr/sbin/httpd -DFOREGROUND ├─18017 /usr/sbin/httpd -DFOREGROUND ├─18018 /usr/sbin/httpd -DFOREGROUND ├─18019 /usr/sbin/httpd -DFOREGROUND ├─18020 /usr/sbin/httpd -DFOREGROUND └─18021 /usr/sbin/httpd -DFOREGROUND Aug 24 10:19:38 centos7.i2tch.loc systemd[1]: Starting The Apache HTTP Server... Aug 24 10:19:38 centos7.i2tch.loc systemd[1]: Started The Apache HTTP Server.
Configuration sous Debian 8
Sous Debian 8 le fichier de configuration principal d'apache est /etc/apache2/apache2.conf. Cette configuration est complémentée par les directives se trouvant dans les fichiers contenus dans les répertoires /etc/apache2/conf-enabled et /etc/apache2/mods-enabled ainsi que par les fichiers /etc/apache2/envvars, /etc/apache2/magic et /etc/apache2/ports.conf :
root@debian8:~# ls -l /etc/apache2/ total 80 -rw-r--r-- 1 root root 7115 Mar 31 10:17 apache2.conf drwxr-xr-x 2 root root 4096 Aug 27 11:08 conf-available drwxr-xr-x 2 root root 4096 Aug 27 11:08 conf-enabled -rw-r--r-- 1 root root 1782 Mar 31 10:17 envvars -rw-r--r-- 1 root root 31063 Mar 30 16:07 magic drwxr-xr-x 2 root root 12288 Aug 27 11:08 mods-available drwxr-xr-x 2 root root 4096 Aug 27 11:08 mods-enabled -rw-r--r-- 1 root root 320 Mar 30 16:07 ports.conf drwxr-xr-x 2 root root 4096 Aug 27 11:08 sites-available drwxr-xr-x 2 root root 4096 Aug 27 11:08 sites-enabled root@debian8:~# root@debian8:~# ls -lR /etc/apache2 /etc/apache2: total 80 -rw-r--r-- 1 root root 7115 Mar 31 10:17 apache2.conf drwxr-xr-x 2 root root 4096 Aug 27 11:08 conf-available drwxr-xr-x 2 root root 4096 Aug 27 11:08 conf-enabled -rw-r--r-- 1 root root 1782 Mar 31 10:17 envvars -rw-r--r-- 1 root root 31063 Mar 30 16:07 magic drwxr-xr-x 2 root root 12288 Aug 27 11:08 mods-available drwxr-xr-x 2 root root 4096 Aug 27 11:08 mods-enabled -rw-r--r-- 1 root root 320 Mar 30 16:07 ports.conf drwxr-xr-x 2 root root 4096 Aug 27 11:08 sites-available drwxr-xr-x 2 root root 4096 Aug 27 11:08 sites-enabled /etc/apache2/conf-available: total 24 -rw-r--r-- 1 root root 315 Mar 30 16:07 charset.conf -rw-r--r-- 1 root root 127 Jul 29 2013 javascript-common.conf -rw-r--r-- 1 root root 3224 Mar 30 16:07 localized-error-pages.conf -rw-r--r-- 1 root root 189 Mar 30 16:07 other-vhosts-access-log.conf -rw-r--r-- 1 root root 2190 Mar 31 10:17 security.conf -rw-r--r-- 1 root root 455 Mar 30 16:07 serve-cgi-bin.conf /etc/apache2/conf-enabled: total 0 lrwxrwxrwx 1 root root 30 Aug 27 11:08 charset.conf -> ../conf-available/charset.conf lrwxrwxrwx 1 root root 44 Aug 27 11:08 localized-error-pages.conf -> ../conf-available/localized-error-pages.conf lrwxrwxrwx 1 root root 46 Aug 27 11:08 other-vhosts-access-log.conf -> ../conf-available/other-vhosts-access-log.conf lrwxrwxrwx 1 root root 31 Aug 27 11:08 security.conf -> ../conf-available/security.conf lrwxrwxrwx 1 root root 36 Aug 27 11:08 serve-cgi-bin.conf -> ../conf-available/serve-cgi-bin.conf /etc/apache2/mods-available: total 528 -rw-r--r-- 1 root root 100 Mar 30 16:07 access_compat.load -rw-r--r-- 1 root root 377 Mar 30 16:07 actions.conf -rw-r--r-- 1 root root 66 Mar 30 16:07 actions.load -rw-r--r-- 1 root root 843 Mar 30 16:07 alias.conf -rw-r--r-- 1 root root 62 Mar 30 16:07 alias.load -rw-r--r-- 1 root root 76 Mar 30 16:07 allowmethods.load -rw-r--r-- 1 root root 76 Mar 30 16:07 asis.load -rw-r--r-- 1 root root 94 Mar 30 16:07 auth_basic.load -rw-r--r-- 1 root root 96 Mar 30 16:07 auth_digest.load -rw-r--r-- 1 root root 100 Mar 30 16:07 auth_form.load -rw-r--r-- 1 root root 72 Mar 30 16:07 authn_anon.load -rw-r--r-- 1 root root 72 Mar 30 16:07 authn_core.load -rw-r--r-- 1 root root 85 Mar 30 16:07 authn_dbd.load -rw-r--r-- 1 root root 70 Mar 30 16:07 authn_dbm.load -rw-r--r-- 1 root root 72 Mar 30 16:07 authn_file.load -rw-r--r-- 1 root root 78 Mar 30 16:07 authn_socache.load -rw-r--r-- 1 root root 74 Mar 30 16:07 authnz_fcgi.load -rw-r--r-- 1 root root 90 Mar 30 16:07 authnz_ldap.load -rw-r--r-- 1 root root 72 Mar 30 16:07 authz_core.load -rw-r--r-- 1 root root 96 Mar 30 16:07 authz_dbd.load -rw-r--r-- 1 root root 92 Mar 30 16:07 authz_dbm.load -rw-r--r-- 1 root root 104 Mar 30 16:07 authz_groupfile.load -rw-r--r-- 1 root root 94 Mar 30 16:07 authz_host.load -rw-r--r-- 1 root root 74 Mar 30 16:07 authz_owner.load -rw-r--r-- 1 root root 94 Mar 30 16:07 authz_user.load -rw-r--r-- 1 root root 3374 Mar 30 16:07 autoindex.conf -rw-r--r-- 1 root root 70 Mar 30 16:07 autoindex.load -rw-r--r-- 1 root root 64 Mar 30 16:07 buffer.load -rw-r--r-- 1 root root 889 Mar 30 16:07 cache_disk.conf -rw-r--r-- 1 root root 89 Mar 30 16:07 cache_disk.load -rw-r--r-- 1 root root 62 Mar 30 16:07 cache.load -rw-r--r-- 1 root root 95 Mar 30 16:07 cache_socache.load -rw-r--r-- 1 root root 115 Mar 30 16:07 cgid.conf -rw-r--r-- 1 root root 60 Mar 30 16:07 cgid.load -rw-r--r-- 1 root root 58 Mar 30 16:07 cgi.load -rw-r--r-- 1 root root 76 Mar 30 16:07 charset_lite.load -rw-r--r-- 1 root root 60 Mar 30 16:07 data.load -rw-r--r-- 1 root root 83 Mar 30 16:07 dav_fs.conf -rw-r--r-- 1 root root 79 Mar 30 16:07 dav_fs.load -rw-r--r-- 1 root root 58 Mar 30 16:07 dav.load -rw-r--r-- 1 root root 68 Mar 30 16:07 dav_lock.load -rw-r--r-- 1 root root 58 Mar 30 16:07 dbd.load -rw-r--r-- 1 root root 522 Mar 31 09:45 deflate.conf -rw-r--r-- 1 root root 84 Mar 30 16:07 deflate.load -rw-r--r-- 1 root root 64 Mar 30 16:07 dialup.load -rw-r--r-- 1 root root 157 Mar 30 16:07 dir.conf -rw-r--r-- 1 root root 58 Mar 30 16:07 dir.load -rw-r--r-- 1 root root 64 Mar 30 16:07 dump_io.load -rw-r--r-- 1 root root 60 Mar 30 16:07 echo.load -rw-r--r-- 1 root root 58 Mar 30 16:07 env.load -rw-r--r-- 1 root root 66 Mar 30 16:07 expires.load -rw-r--r-- 1 root root 72 Mar 30 16:07 ext_filter.load -rw-r--r-- 1 root root 89 Mar 30 16:07 file_cache.load -rw-r--r-- 1 root root 64 Mar 30 16:07 filter.load -rw-r--r-- 1 root root 66 Mar 30 16:07 headers.load -rw-r--r-- 1 root root 176 Mar 30 16:07 heartbeat.load -rw-r--r-- 1 root root 182 Mar 30 16:07 heartmonitor.load -rw-r--r-- 1 root root 62 Mar 30 16:07 ident.load -rw-r--r-- 1 root root 82 Mar 30 16:07 include.load -rw-r--r-- 1 root root 402 Mar 30 16:07 info.conf -rw-r--r-- 1 root root 60 Mar 30 16:07 info.load -rw-r--r-- 1 root root 116 Mar 30 16:07 lbmethod_bybusyness.load -rw-r--r-- 1 root root 116 Mar 30 16:07 lbmethod_byrequests.load -rw-r--r-- 1 root root 114 Mar 30 16:07 lbmethod_bytraffic.load -rw-r--r-- 1 root root 114 Mar 30 16:07 lbmethod_heartbeat.load -rw-r--r-- 1 root root 121 Mar 30 16:07 ldap.conf -rw-r--r-- 1 root root 60 Mar 30 16:07 ldap.load -rw-r--r-- 1 root root 70 Mar 30 16:07 log_debug.load -rw-r--r-- 1 root root 76 Mar 30 16:07 log_forensic.load -rw-r--r-- 1 root root 58 Mar 30 16:07 lua.load -rw-r--r-- 1 root root 62 Mar 30 16:07 macro.load -rw-r--r-- 1 root root 7639 Mar 31 09:45 mime.conf -rw-r--r-- 1 root root 60 Mar 30 16:07 mime.load -rw-r--r-- 1 root root 120 Mar 30 16:07 mime_magic.conf -rw-r--r-- 1 root root 72 Mar 30 16:07 mime_magic.load -rw-r--r-- 1 root root 668 Mar 30 16:07 mpm_event.conf -rw-r--r-- 1 root root 106 Mar 30 16:07 mpm_event.load -rw-r--r-- 1 root root 571 Mar 30 16:07 mpm_prefork.conf -rw-r--r-- 1 root root 108 Mar 30 16:07 mpm_prefork.load -rw-r--r-- 1 root root 836 Mar 30 16:07 mpm_worker.conf -rw-r--r-- 1 root root 107 Mar 30 16:07 mpm_worker.load -rw-r--r-- 1 root root 724 Mar 30 16:07 negotiation.conf -rw-r--r-- 1 root root 74 Mar 30 16:07 negotiation.load -rw-r--r-- 1 root root 87 Mar 30 16:07 proxy_ajp.load -rw-r--r-- 1 root root 347 Mar 30 16:07 proxy_balancer.conf -rw-r--r-- 1 root root 115 Mar 30 16:07 proxy_balancer.load -rw-r--r-- 1 root root 822 Mar 30 16:07 proxy.conf -rw-r--r-- 1 root root 95 Mar 30 16:07 proxy_connect.load -rw-r--r-- 1 root root 95 Mar 30 16:07 proxy_express.load -rw-r--r-- 1 root root 89 Mar 30 16:07 proxy_fcgi.load -rw-r--r-- 1 root root 93 Mar 30 16:07 proxy_fdpass.load -rw-r--r-- 1 root root 189 Mar 30 16:07 proxy_ftp.conf -rw-r--r-- 1 root root 87 Mar 30 16:07 proxy_ftp.load -rw-r--r-- 1 root root 2511 Mar 30 16:07 proxy_html.conf -rw-r--r-- 1 root root 89 Mar 31 10:17 proxy_html.load -rw-r--r-- 1 root root 89 Mar 30 16:07 proxy_http.load -rw-r--r-- 1 root root 62 Mar 30 16:07 proxy.load -rw-r--r-- 1 root root 89 Mar 30 16:07 proxy_scgi.load -rw-r--r-- 1 root root 97 Mar 30 16:07 proxy_wstunnel.load -rw-r--r-- 1 root root 85 Mar 30 16:07 ratelimit.load -rw-r--r-- 1 root root 70 Mar 30 16:07 reflector.load -rw-r--r-- 1 root root 68 Mar 30 16:07 remoteip.load -rw-r--r-- 1 root root 1190 Mar 30 16:07 reqtimeout.conf -rw-r--r-- 1 root root 72 Mar 30 16:07 reqtimeout.load -rw-r--r-- 1 root root 66 Mar 30 16:07 request.load -rw-r--r-- 1 root root 66 Mar 30 16:07 rewrite.load -rw-r--r-- 1 root root 58 Mar 30 16:07 sed.load -rw-r--r-- 1 root root 99 Mar 30 16:07 session_cookie.load -rw-r--r-- 1 root root 99 Mar 30 16:07 session_crypto.load -rw-r--r-- 1 root root 93 Mar 30 16:07 session_dbd.load -rw-r--r-- 1 root root 66 Mar 30 16:07 session.load -rw-r--r-- 1 root root 1280 Mar 30 16:07 setenvif.conf -rw-r--r-- 1 root root 68 Mar 30 16:07 setenvif.load -rw-r--r-- 1 root root 78 Mar 30 16:07 slotmem_plain.load -rw-r--r-- 1 root root 74 Mar 30 16:07 slotmem_shm.load -rw-r--r-- 1 root root 74 Mar 30 16:07 socache_dbm.load -rw-r--r-- 1 root root 84 Mar 30 16:07 socache_memcache.load -rw-r--r-- 1 root root 78 Mar 30 16:07 socache_shmcb.load -rw-r--r-- 1 root root 66 Mar 30 16:07 speling.load -rw-r--r-- 1 root root 3110 Mar 30 16:07 ssl.conf -rw-r--r-- 1 root root 97 Mar 30 16:07 ssl.load -rw-r--r-- 1 root root 749 Mar 30 16:07 status.conf -rw-r--r-- 1 root root 64 Mar 30 16:07 status.load -rw-r--r-- 1 root root 72 Mar 30 16:07 substitute.load -rw-r--r-- 1 root root 64 Mar 30 16:07 suexec.load -rw-r--r-- 1 root root 70 Mar 30 16:07 unique_id.load -rw-r--r-- 1 root root 423 Mar 31 10:17 userdir.conf -rw-r--r-- 1 root root 66 Mar 30 16:07 userdir.load -rw-r--r-- 1 root root 70 Mar 30 16:07 usertrack.load -rw-r--r-- 1 root root 74 Mar 30 16:07 vhost_alias.load -rw-r--r-- 1 root root 66 Mar 30 16:07 xml2enc.load /etc/apache2/mods-enabled: total 0 lrwxrwxrwx 1 root root 36 Aug 27 11:08 access_compat.load -> ../mods-available/access_compat.load lrwxrwxrwx 1 root root 28 Aug 27 11:08 alias.conf -> ../mods-available/alias.conf lrwxrwxrwx 1 root root 28 Aug 27 11:08 alias.load -> ../mods-available/alias.load lrwxrwxrwx 1 root root 33 Aug 27 11:08 auth_basic.load -> ../mods-available/auth_basic.load lrwxrwxrwx 1 root root 33 Aug 27 11:08 authn_core.load -> ../mods-available/authn_core.load lrwxrwxrwx 1 root root 33 Aug 27 11:08 authn_file.load -> ../mods-available/authn_file.load lrwxrwxrwx 1 root root 33 Aug 27 11:08 authz_core.load -> ../mods-available/authz_core.load lrwxrwxrwx 1 root root 33 Aug 27 11:08 authz_host.load -> ../mods-available/authz_host.load lrwxrwxrwx 1 root root 33 Aug 27 11:08 authz_user.load -> ../mods-available/authz_user.load lrwxrwxrwx 1 root root 32 Aug 27 11:08 autoindex.conf -> ../mods-available/autoindex.conf lrwxrwxrwx 1 root root 32 Aug 27 11:08 autoindex.load -> ../mods-available/autoindex.load lrwxrwxrwx 1 root root 30 Aug 27 11:08 deflate.conf -> ../mods-available/deflate.conf lrwxrwxrwx 1 root root 30 Aug 27 11:08 deflate.load -> ../mods-available/deflate.load lrwxrwxrwx 1 root root 26 Aug 27 11:08 dir.conf -> ../mods-available/dir.conf lrwxrwxrwx 1 root root 26 Aug 27 11:08 dir.load -> ../mods-available/dir.load lrwxrwxrwx 1 root root 26 Aug 27 11:08 env.load -> ../mods-available/env.load lrwxrwxrwx 1 root root 29 Aug 27 11:08 filter.load -> ../mods-available/filter.load lrwxrwxrwx 1 root root 27 Aug 27 11:08 mime.conf -> ../mods-available/mime.conf lrwxrwxrwx 1 root root 27 Aug 27 11:08 mime.load -> ../mods-available/mime.load lrwxrwxrwx 1 root root 32 Aug 27 11:08 mpm_event.conf -> ../mods-available/mpm_event.conf lrwxrwxrwx 1 root root 32 Aug 27 11:08 mpm_event.load -> ../mods-available/mpm_event.load lrwxrwxrwx 1 root root 34 Aug 27 11:08 negotiation.conf -> ../mods-available/negotiation.conf lrwxrwxrwx 1 root root 34 Aug 27 11:08 negotiation.load -> ../mods-available/negotiation.load lrwxrwxrwx 1 root root 33 Aug 27 11:08 reqtimeout.conf -> ../mods-available/reqtimeout.conf lrwxrwxrwx 1 root root 33 Aug 27 11:08 reqtimeout.load -> ../mods-available/reqtimeout.load lrwxrwxrwx 1 root root 31 Aug 27 11:08 setenvif.conf -> ../mods-available/setenvif.conf lrwxrwxrwx 1 root root 31 Aug 27 11:08 setenvif.load -> ../mods-available/setenvif.load lrwxrwxrwx 1 root root 29 Aug 27 11:08 status.conf -> ../mods-available/status.conf lrwxrwxrwx 1 root root 29 Aug 27 11:08 status.load -> ../mods-available/status.load /etc/apache2/sites-available: total 12 -rw-r--r-- 1 root root 1332 Mar 30 16:07 000-default.conf -rw-r--r-- 1 root root 6437 Mar 31 10:17 default-ssl.conf /etc/apache2/sites-enabled: total 0 lrwxrwxrwx 1 root root 35 Aug 27 11:08 000-default.conf -> ../sites-available/000-default.conf
/etc/apache2/apache2.conf
root@debian8:~# cat /etc/apache2/apache2.conf # This is the main Apache server configuration file. It contains the # configuration directives that give the server its instructions. # See http://httpd.apache.org/docs/2.4/ for detailed information about # the directives and /usr/share/doc/apache2/README.Debian about Debian specific # hints. # # # Summary of how the Apache 2 configuration works in Debian: # The Apache 2 web server configuration in Debian is quite different to # upstream's suggested way to configure the web server. This is because Debian's # default Apache2 installation attempts to make adding and removing modules, # virtual hosts, and extra configuration directives as flexible as possible, in # order to make automating the changes and administering the server as easy as # possible. # It is split into several files forming the configuration hierarchy outlined # below, all located in the /etc/apache2/ directory: # # /etc/apache2/ # |-- apache2.conf # | `-- ports.conf # |-- mods-enabled # | |-- *.load # | `-- *.conf # |-- conf-enabled # | `-- *.conf # `-- sites-enabled # `-- *.conf # # # * apache2.conf is the main configuration file (this file). It puts the pieces # together by including all remaining configuration files when starting up the # web server. # # * ports.conf is always included from the main configuration file. It is # supposed to determine listening ports for incoming connections which can be # customized anytime. # # * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/ # directories contain particular configuration snippets which manage modules, # global configuration fragments, or virtual host configurations, # respectively. # # They are activated by symlinking available configuration files from their # respective *-available/ counterparts. These should be managed by using our # helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See # their respective man pages for detailed information. # # * The binary is called apache2. Due to the use of environment variables, in # the default configuration, apache2 needs to be started/stopped with # /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not # work with the default configuration. # Global configuration # # # ServerRoot: The top of the directory tree under which the server's # configuration, error, and log files are kept. # # NOTE! If you intend to place this on an NFS (or otherwise network) # mounted filesystem then please read the Mutex documentation (available # at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>); # you will save yourself a lot of trouble. # # Do NOT add a slash at the end of the directory path. # #ServerRoot "/etc/apache2" # # The accept serialization lock file MUST BE STORED ON A LOCAL DISK. # Mutex file:${APACHE_LOCK_DIR} default # # PidFile: The file in which the server should record its process # identification number when it starts. # This needs to be set in /etc/apache2/envvars # PidFile ${APACHE_PID_FILE} # # Timeout: The number of seconds before receives and sends time out. # Timeout 300 # # KeepAlive: Whether or not to allow persistent connections (more than # one request per connection). Set to "Off" to deactivate. # KeepAlive On # # MaxKeepAliveRequests: The maximum number of requests to allow # during a persistent connection. Set to 0 to allow an unlimited amount. # We recommend you leave this number high, for maximum performance. # MaxKeepAliveRequests 100 # # KeepAliveTimeout: Number of seconds to wait for the next request from the # same client on the same connection. # KeepAliveTimeout 5 # These need to be set in /etc/apache2/envvars User ${APACHE_RUN_USER} Group ${APACHE_RUN_GROUP} # # HostnameLookups: Log the names of clients or just their IP addresses # e.g., www.apache.org (on) or 204.62.129.132 (off). # The default is off because it'd be overall better for the net if people # had to knowingly turn this feature on, since enabling it means that # each client request will result in AT LEAST one lookup request to the # nameserver. # HostnameLookups Off # ErrorLog: The location of the error log file. # If you do not specify an ErrorLog directive within a <VirtualHost> # container, error messages relating to that virtual host will be # logged here. If you *do* define an error logfile for a <VirtualHost> # container, that host's errors will be logged there and not here. # ErrorLog ${APACHE_LOG_DIR}/error.log # # LogLevel: Control the severity of messages logged to the error_log. # Available values: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the log level for particular modules, e.g. # "LogLevel info ssl:warn" # LogLevel warn # Include module configuration: IncludeOptional mods-enabled/*.load IncludeOptional mods-enabled/*.conf # Include list of ports to listen on Include ports.conf # Sets the default security model of the Apache2 HTTPD server. It does # not allow access to the root filesystem outside of /usr/share and /var/www. # The former is used by web applications packaged in Debian, # the latter may be used for local directories served by the web server. If # your system is serving content from a sub-directory in /srv you must allow # access here, or in any related virtual host. <Directory /> Options FollowSymLinks AllowOverride None Require all denied </Directory> <Directory /usr/share> AllowOverride None Require all granted </Directory> <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> #<Directory /srv/> # Options Indexes FollowSymLinks # AllowOverride None # Require all granted #</Directory> # AccessFileName: The name of the file to look for in each directory # for additional configuration directives. See also the AllowOverride # directive. # AccessFileName .htaccess # # The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients. # <FilesMatch "^\.ht"> Require all denied </FilesMatch> # # The following directives define some format nicknames for use with # a CustomLog directive. # # These deviate from the Common Log Format definitions in that they use %O # (the actual bytes sent including headers) instead of %b (the size of the # requested file), because the latter makes it impossible to detect partial # requests. # # Note that the use of %{X-Forwarded-For}i instead of %h is not recommended. # Use mod_remoteip instead. # LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %O" common LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent # Include of directories ignores editors' and dpkg's backup files, # see README.Debian for details. # Include generic snippets of statements IncludeOptional conf-enabled/*.conf # Include the virtual host configurations: IncludeOptional sites-enabled/*.conf # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
/etc/apache2/conf-available/charset.conf
root@debian8:~# cat /etc/apache2/conf-available/charset.conf # Read the documentation before enabling AddDefaultCharset. # In general, it is only a good idea if you know that all your files # have this encoding. It will override any encoding given in the files # in meta http-equiv or xml encoding tags. #AddDefaultCharset UTF-8 # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
/etc/apache2/conf-available/localized-error-pages.conf
root@debian8:~# cat /etc/apache2/conf-available/localized-error-pages.conf # Customizable error responses come in three flavors: # 1) plain text # 2) local redirects # 3) external redirects # # Some examples: #ErrorDocument 500 "The server made a boo boo." #ErrorDocument 404 /missing.html #ErrorDocument 404 "/cgi-bin/missing_handler.pl" #ErrorDocument 402 http://www.example.com/subscription_info.html # # # Putting this all together, we can internationalize error responses. # # We use Alias to redirect any /error/HTTP_<error>.html.var response to # our collection of by-error message multi-language collections. We use # includes to substitute the appropriate text. # # You can modify the messages' appearance without changing any of the # default HTTP_<error>.html.var files by adding the line: # #Alias /error/include/ "/your/include/path/" # # which allows you to create your own set of files by starting with the # /usr/share/apache2/error/include/ files and copying them to /your/include/path/, # even on a per-VirtualHost basis. If you include the Alias in the global server # context, is has to come _before_ the 'Alias /error/ ...' line. # # The default include files will display your Apache version number and your # ServerAdmin email address regardless of the setting of ServerSignature. # # WARNING: The configuration below will NOT work out of the box if you have a # SetHandler directive in a <Location /> context somewhere. Adding # the following three lines AFTER the <Location /> context should # make it work in most cases: # <Location /error/> # SetHandler none # </Location> # # The internationalized error documents require mod_alias, mod_include # and mod_negotiation. To activate them, uncomment the following 37 lines. #<IfModule mod_negotiation.c> # <IfModule mod_include.c> # <IfModule mod_alias.c> # # Alias /error/ "/usr/share/apache2/error/" # # <Directory "/usr/share/apache2/error"> # Options IncludesNoExec # AddOutputFilter Includes html # AddHandler type-map var # Order allow,deny # Allow from all # LanguagePriority en cs de es fr it nl sv pt-br ro # ForceLanguagePriority Prefer Fallback # </Directory> # # ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var # ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var # ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var # ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var # ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var # ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var # ErrorDocument 410 /error/HTTP_GONE.html.var # ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var # ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var # ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var # ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var # ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var # ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var # ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var # ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var # ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var # ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var # </IfModule> # </IfModule> #</IfModule> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
/etc/apache2/conf-available/other-vhosts-access-log.conf
root@debian8:~# cat /etc/apache2/conf-available/other-vhosts-access-log.conf # Define an access log for VirtualHosts that don't define their own logfile CustomLog ${APACHE_LOG_DIR}/other_vhosts_access.log vhost_combined # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
/etc/apache2/conf-available/security.conf
root@debian8:~# cat /etc/apache2/conf-available/security.conf # # Disable access to the entire file system except for the directories that # are explicitly allowed later. # # This currently breaks the configurations that come with some web application # Debian packages. # #<Directory /> # AllowOverride None # Order Deny,Allow # Deny from all #</Directory> # Changing the following options will not really affect the security of the # server, but might make attacks slightly more difficult in some cases. # # ServerTokens # This directive configures what you return as the Server HTTP response # Header. The default is 'Full' which sends information about the OS-Type # and compiled in modules. # Set to one of: Full | OS | Minimal | Minor | Major | Prod # where Full conveys the most information, and Prod the least. #ServerTokens Minimal ServerTokens OS #ServerTokens Full # # Optionally add a line containing the server version and virtual host # name to server-generated pages (internal error documents, FTP directory # listings, mod_status and mod_info output etc., but not CGI generated # documents or custom error documents). # Set to "EMail" to also include a mailto: link to the ServerAdmin. # Set to one of: On | Off | EMail #ServerSignature Off ServerSignature On # # Allow TRACE method # # Set to "extended" to also reflect the request body (only for testing and # diagnostic purposes). # # Set to one of: On | Off | extended TraceEnable Off #TraceEnable On # # Forbid access to version control directories # # If you use version control systems in your document root, you should # probably deny access to their directories. For example, for subversion: # #<DirectoryMatch "/\.svn"> # Require all denied #</DirectoryMatch> # # Setting this header will prevent MSIE from interpreting files as something # else than declared by the content type in the HTTP headers. # Requires mod_headers to be enabled. # #Header set X-Content-Type-Options: "nosniff" # # Setting this header will prevent other sites from embedding pages from this # site as frames. This defends against clickjacking attacks. # Requires mod_headers to be enabled. # #Header set X-Frame-Options: "sameorigin" # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
/etc/apache2/conf-available/serve-cgi-bin.conf
root@debian8:~# cat /etc/apache2/conf-available/serve-cgi-bin.conf <IfModule mod_alias.c> <IfModule mod_cgi.c> Define ENABLE_USR_LIB_CGI_BIN </IfModule> <IfModule mod_cgid.c> Define ENABLE_USR_LIB_CGI_BIN </IfModule> <IfDefine ENABLE_USR_LIB_CGI_BIN> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Require all granted </Directory> </IfDefine> </IfModule> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
/etc/apache2/envvars
root@debian8:~# cat /etc/apache2/envvars # envvars - default environment variables for apache2ctl # this won't be correct after changing uid unset HOME # for supporting multiple apache2 instances if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}" else SUFFIX= fi # Since there is no sane way to get the parsed apache2 config in scripts, some # settings are defined via environment variables and then used in apache2ctl, # /etc/init.d/apache2, /etc/logrotate.d/apache2, etc. export APACHE_RUN_USER=www-data export APACHE_RUN_GROUP=www-data # temporary state file location. This might be changed to /run in Wheezy+1 export APACHE_PID_FILE=/var/run/apache2/apache2$SUFFIX.pid export APACHE_RUN_DIR=/var/run/apache2$SUFFIX export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX # Only /var/log/apache2 is handled by /etc/logrotate.d/apache2. export APACHE_LOG_DIR=/var/log/apache2$SUFFIX ## The locale used by some modules like mod_dav export LANG=C ## Uncomment the following line to use the system default locale instead: #. /etc/default/locale export LANG ## The command to get the status for 'apache2ctl status'. ## Some packages providing 'www-browser' need '--dump' instead of '-dump'. #export APACHE_LYNX='www-browser -dump' ## If you need a higher file descriptor limit, uncomment and adjust the ## following line (default is 8192): #APACHE_ULIMIT_MAX_FILES='ulimit -n 65536' ## If you would like to pass arguments to the web server, add them below ## to the APACHE_ARGUMENTS environment. #export APACHE_ARGUMENTS='' ## Enable the debug mode for maintainer scripts. ## This will produce a verbose output on package installations of web server modules and web application ## installations which interact with Apache #export APACHE2_MAINTSCRIPT_DEBUG=1
/etc/apache2/magic
root@debian8:~# more /etc/apache2/magic # Magic data for mod_mime_magic (originally for file(1) command) # # The format is 4-5 columns: # Column #1: byte number to begin checking from, ">" indicates continuation # Column #2: type of data to match # Column #3: contents of data to match # Column #4: MIME type of result # Column #5: MIME encoding of result (optional) #------------------------------------------------------------------------------ # Localstuff: file(1) magic for locally observed files # Add any locally observed files here. # Real Audio (Magic .ra\0375) 0 belong 0x2e7261fd audio/x-pn-realaudio 0 string .RMF application/vnd.rn-realmedia #video/x-pn-realvideo #video/vnd.rn-realvideo #application/vnd.rn-realmedia # sigh, there are many mimes for that but the above are the most common. # Taken from magic, converted to magic.mime # mime types according to http://www.geocities.com/nevilo/mod.htm: # audio/it .it # audio/x-zipped-it .itz # audio/xm fasttracker modules # audio/x-s3m screamtracker modules # audio/s3m screamtracker modules # audio/x-zipped-mod mdz # audio/mod mod # audio/x-mod All modules (mod, s3m, 669, mtm, med, xm, it, mdz, stm, itz, xmz, s3z) # Taken from loader code from mikmod version 2.14 # by Steve McIntyre (stevem@chiark.greenend.org.uk) # <doj@cubic.org> added title printing on 2003-06-24 0 string MAS_UTrack_V00 >14 string >/0 audio/x-mod #audio/x-tracker-module --More--(4%)
/etc/apache2/ports.conf
root@debian8:~# cat /etc/apache2/ports.conf # If you just change the port or add more ports here, you will likely also # have to change the VirtualHost statement in # /etc/apache2/sites-enabled/000-default.conf Listen 80 <IfModule ssl_module> Listen 443 </IfModule> <IfModule mod_gnutls.c> Listen 443 </IfModule> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Administration de Base
LAB #1 - Gestion de serveurs virtuels
Apache est capable de gérer de multiples sites hébergés sur la même machine.
Il existe deux façons de créer des sites ( hôtes ) virtuels :
- Hôte Virtuel par nom
- Hôte Virtuel par adresse IP
Sous RHEL / CentOS 7
Sous RHEL / CentOS 7 ceci est rendu possible par un fichier de configuration spécifique appelé: /etc/httpd/conf/vhosts.d/Vhosts.conf. Le répertoire /etc/httpd/conf/vhosts.d/ n'existant pas, créez-le:
[root@centos7 ~]# mkdir /etc/httpd/conf/vhosts.d/
Créez ensuite le fichier /etc/httpd/conf/vhosts.d/Vhosts.conf :
[root@centos7 ~]# touch /etc/httpd/conf/vhosts.d/Vhosts.conf
Le contenu de fichier est inclus à l'intérieur de la configuration d'apache grâce à la directive suivante du fichier httpd.conf:
... # Supplemental configuration # # Load config files in the "/etc/httpd/conf.d" directory, if any. IncludeOptional conf.d/*.conf Include conf/vhosts.d/*.conf
Ajoutez donc cette ligne au fichier /etc/httpd/conf/httpd.conf.
Hôte virtuel par nom
Nous allons d'abord considérer les sites virtuels par nom.
Créez un répertoire /www/site1 à la racine de votre arborescence pour héberger notre premier hôte virtuel :
[root@centos7 ~]# mkdir -p /www/site1
Créez ensuite le fichier index.html du répertoire /www/site1:
[root@centos7 ~]# vi /www/site1/index.html [root@centos7 ~]# cat /www/site1/index.html <html> <head> <title>Page de Test</title> <body> <center>Accueil du site 1</center> </body> </html>
Editez le fichier /etc/httpd/conf/vhosts.d/Vhosts.conf en suivant l'exemple ci-dessous :
[root@centos7 ~]# vi /etc/httpd/conf/vhosts.d/Vhosts.conf [root@centos7 ~]# cat /etc/httpd/conf/vhosts.d/Vhosts.conf ################# Named VirtualHosts NameVirtualHost *:80 ##################Default Site Virtual Host <VirtualHost *:80> DocumentRoot /var/www/html ServerName i2tch.loc ServerAlias www.i2tch.loc </VirtualHost> ##################www.rhelnom.com <VirtualHost *:80> ServerName www.rhelnom.com DirectoryIndex index.html DocumentRoot /www/site1 <Directory /www/site1> Require all granted </Directory> </VirtualHost>
Important : Notez qu'apache servira toujours le contenu da la première section des sites virtuels par défaut, sauf précision de la part de l'internaute. Il est donc impératif d'ajouter une section VirtualHost pour votre site par défaut.
Redémarrez ensuite le serveur Apache :
[root@centos7 ~]# systemctl restart httpd
Avant de pouvoir consulter le site virtuel, il faut renseigner votre fichier /etc/hosts :
[root@centos7 ~]# vi /etc/hosts [root@centos7 ~]# cat /etc/hosts 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 10.0.2.15 i2tch.loc 10.0.2.15 www.i2tch.loc 10.0.2.15 www.rhelnom.com
Sauvegardez votre fichier hosts et installez le navigateur web en mode texte lynx :
[root@centos7 ~]# yum install lynx
Testez votre configuration avec lynx :
[root@centos7 ~]# lynx --dump http://www.rhelnom.com Accueil du site 1 [root@centos7 ~]#
Afin de mieux comprendre les visites à notre site virtuel, nous avons besoin d'un fichier log ainsi qu'un fichier de log des erreurs. Ouvrez donc le fichier /etc/httpd/conf/vhosts.d/Vhosts.conf et ajoutez les deux lignes suivantes:
Customlog /www/logs/site1/rhelnom.log combined Errorlog /www/logs/site1/rhelnom_error.log
Vous obtiendrez une fenêtre similaire à celle-ci :
[root@centos7 ~]# vi /etc/httpd/conf/vhosts.d/Vhosts.conf [root@centos7 ~]# cat /etc/httpd/conf/vhosts.d/Vhosts.conf ################# Named VirtualHosts NameVirtualHost *:80 ##################Default Site Virtual Host <VirtualHost *:80> DocumentRoot /var/www/html ServerName i2tch.loc ServerAlias www.i2tch.loc </VirtualHost> ##################www.rhelnom.com <VirtualHost *:80> ServerName www.rhelnom.com DirectoryIndex index.html DocumentRoot /www/site1 Customlog /www/logs/site1/rhelnom.log combined Errorlog /www/logs/site1/rhelnom_error.log <Directory /www/site1> Require all granted </Directory> </VirtualHost>
Créez ensuite le répertoire /www/logs/site1 :
[root@centos7 ~]# mkdir -p /www/logs/site1
Redémarrez le serveur Apache :
[root@centos7 ~]# systemctl restart httpd
Testez votre configuration avec lynx :
[root@centos7 ~]# lynx --dump http://www.rhelnom.com Accueil du site 1 [root@centos7 ~]#
Contrôlez maintenant le contenu du répertoire /www/logs/site1. Vous devez y retrouver deux fichiers :
[root@centos7 ~]# ls -l /www/logs/site1/ total 4 -rw-r--r--. 1 root root 0 Aug 24 11:06 rhelnom_error.log -rw-r--r--. 1 root root 138 Aug 24 11:06 rhelnom.log
Ces deux fichiers rhelnom.log et rhelnom_error.log sont créés automatiquement par Apache.
En contrôlant le contenu du fichier /www/logs/site1/rhelnom.log nous constatons que le log a été généré :
[root@centos7 ~]# cat /www/logs/site1/rhelnom.log 10.0.2.15 - - [24/Aug/2017:11:06:47 +0200] "GET / HTTP/1.0" 200 100 "-" "Lynx/2.8.8dev.15 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/1.0.1e-fips"
Hôte virtuel par adresse IP
Commencez par créer une adresse IP fixe :
[root@centos7 ~]# nmcli connection add con-name ip_fixe ifname enp0s3 type ethernet ip4 10.0.2.16/24 gw4 10.0.2.2 [root@centos7 ~]# nmcli connection up ip_fixe [root@centos7 ~]# nmcli connection mod ip_fixe ipv4.dns 8.8.8.8 [root@centos7 ~]# systemctl restart NetworkManager [root@centos7 ~]# nslookup www.free.fr Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: www.free.fr Address: 212.27.48.10
Avant de pouvoir consulter les sites virtuel, il faut modifier votre fichier /etc/hosts :
[root@centos7 ~]# vi /etc/hosts [root@centos7 ~]# cat /etc/hosts 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 10.0.2.16 i2tch.loc 10.0.2.16 www.i2tch.loc 10.0.2.16 www.rhelnom.com
Vous allez maintenant procéder à la création d'un site ( hôte ) virtuel par adresse IP. Normalement, votre serveur serait muni de deux cartes réseaux permettant ainsi d'attribuer un site ou hôte virtuel par numéro IP. Cependant, dans le cas suivant vous allez tout simplement affecté deux numéros IP à la même carte afin de procéder aux tests. Pour faire ceci, vous devez associer une deuxième adresse IP à votre carte réseau enp0s3. Saisissez donc la commande suivante dans une fenêtre de console en tant que root :
[root@centos7 ~]# ip a | grep 'inet ' inet 127.0.0.1/8 scope host lo inet 10.0.2.16/24 brd 10.0.2.255 scope global enp0s3 [root@centos7 ~]# ip a add 192.168.1.99/24 dev enp0s3 [root@centos7 ~]# ip a | grep 'inet ' inet 127.0.0.1/8 scope host lo inet 10.0.2.16/24 brd 10.0.2.255 scope global enp0s3 inet 192.168.1.99/24 scope global enp0s3
Créez maintenant le répertoire pour notre site2 :
[root@centos7 ~]# mkdir /www/site2
Créez la page d'accueil :
[root@centos7 ~]# vi /www/site2/index.html [root@centos7 ~]# cat /www/site2/index.html <html> <head> <title>Page de Test</title> <body> <center>Accueil du site 2</center> </body> </html>
Créez ensuite le répertoire /www/logs/site2 :
[root@centos7 ~]# mkdir /www/logs/site2
Editez maintenant le fichier /etc/httpd/conf/vhosts.d/Vhosts.conf:
[root@centos7 ~]# vi /etc/httpd/conf/vhosts.d/Vhosts.conf [root@centos7 ~]# cat /etc/httpd/conf/vhosts.d/Vhosts.conf ################# IP-based Virtual Hosts <VirtualHost 192.168.1.99> DocumentRoot /www/site2 ServerName www.rhelip.com DirectoryIndex index.html Customlog /www/logs/site2/rhelip.log combined Errorlog /www/logs/site2/rhelip_error.log <Directory /www/site2> Require all granted </Directory> </VirtualHost> ################# Named VirtualHosts NameVirtualHost *:80 ##################Default Site Virtual Host <VirtualHost *:80> DocumentRoot /var/www/html ServerName i2tch.loc ServerAlias www.i2tch.loc </VirtualHost> ##################www.rhelnom.com <VirtualHost *:80> ServerName www.rhelnom.com DirectoryIndex index.html DocumentRoot /www/site1 Customlog /www/logs/site1/rhelnom.log combined Errorlog /www/logs/site1/rhelnom_error.log <Directory /www/site1> Require all granted </Directory> </VirtualHost>
Éditez ensuite le fichier /etc/hosts :
[root@centos7 ~]# vi /etc/hosts [root@centos7 ~]# cat /etc/hosts 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 10.0.2.16 i2tch.loc 10.0.2.16 www.i2tch.loc 10.0.2.16 www.rhelnom.com 192.168.1.99 www.rhelip.com
Redémarrez votre serveur Apache :
[root@centos7 ~]# systemctl restart httpd
Testez votre configuration avec lynx :
[root@centos7 ~]# lynx --dump http://www.rhelip.com Accueil du site 2 [root@centos7 ~]#
Consultez maintenant le répertoire /www/logs/site2. Vous constaterez l'apparition d'un fichier log pour le site www.rhelip.com :
total 4 -rw-r--r--. 1 root root 0 Aug 24 14:28 rhelip_error.log -rw-r--r--. 1 root root 141 Aug 24 14:29 rhelip.log
Hôtes Virtuels Dynamiques avec mod_vhost_alias
Commencez par installer le paquet dnsmasq afin de fournir les services d'un serveur DNS :
[root@centos7 ~]# yum install dnsmasq
Créez le fichier /etc/dnsmasq.d/i2tch pour indiquer à dnsmasq que le domaine i2tch.loc se trouve à l'adresse 127.0.0.1 :
[root@centos7 ~]# vi /etc/dnsmasq.d/i2tch [root@centos7 ~]# cat /etc/dnsmasq.d/i2tch listen-address=127.0.0.1 address=/.i2tch.loc/127.0.0.1
Re-démarrez le service dnsmasq pour prendre en compte vos modifications :
[root@centos7 ~]# systemctl restart dnsmasq
Pour qu'apache puisse gérer les hôtes virtuels dynamiques, il faut que les modules mod_rewrite et mod_vhost_alias soient activés dans le fichier /etc/httpd/conf.modules.d/00-base.conf :
[root@centos7 ~]# cat /etc/httpd/conf.modules.d/00-base.conf | grep rewrite LoadModule rewrite_module modules/mod_rewrite.so [root@centos7 ~]# cat /etc/httpd/conf.modules.d/00-base.conf | grep alias LoadModule alias_module modules/mod_alias.so LoadModule vhost_alias_module modules/mod_vhost_alias.so
Editez maintenant la section Default Site Virtual Host du fichier /etc/httpd/conf/vhosts.d/Vhosts.conf :
[root@centos7 ~]# vi /etc/httpd/conf/vhosts.d/Vhosts.conf [root@centos7 ~]# cat /etc/httpd/conf/vhosts.d/Vhosts.conf ################# IP-based Virtual Hosts <VirtualHost 192.168.1.99> DocumentRoot /www/site2 ServerName www.rhelip.com DirectoryIndex index.html Customlog /www/logs/site2/rhelip.log combined Errorlog /www/logs/site2/rhelip_error.log <Directory /www/site2> Require all granted </Directory> </VirtualHost> ################# Named VirtualHosts NameVirtualHost *:80 ##################Default Site Virtual Host <VirtualHost *:80> VirtualDocumentRoot /var/www/html/%-3 ServerName i2tch.loc ServerAlias *.i2tch.loc ServerAdmin webmaster@localhost LogLevel info <Directory /> Options FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost> ##################www.rhelnom.com <VirtualHost *:80> ServerName www.rhelnom.com DirectoryIndex index.html DocumentRoot /www/site1 Customlog /www/logs/site1/rhelnom.log combined Errorlog /www/logs/site1/rhelnom_error.log <Directory /www/site1> Require all granted </Directory> </VirtualHost>
Créez le fichier /var/www/html/.htaccess afin d'activer la ré-écriture des URLs :
[root@centos7 ~]# vi /var/www/html/.htaccess [root@centos7 ~]# cat /var/www/html/.htaccess RewriteEngine On RewriteBase /
Re-démarrez le serveur httpd :
[root@centos7 ~]# systemctl restart httpd
Creéz maintenant le répertoire /var/www/html/_ pour contenir le site par défaut :
[root@centos7 ~]# mkdir /var/www/html/_
Créez la page d'accueil du site par défaut :
[root@centos7 ~]# vi /var/www/html/_/index.html [root@centos7 ~]# cat /var/www/html/_/index.html <html> <body> <center>Accueil du site par défaut</center> </body> </html>
Créez deux sites projecta et projectb :
[root@centos7 ~]# mkdir /var/www/html/projecta [root@centos7 ~]# vi /var/www/html/projecta/index.html [root@centos7 ~]# cat /var/www/html/projecta/index.html <html> <body> <center>Accueil du Project A</center> </body> </html>
[root@centos7 ~]# mkdir /var/www/html/projectb [root@centos7 ~]# vi /var/www/html/projectb/index.html [root@centos7 ~]# cat /var/www/html/projectb/index.html <html> <body> <center>Accueil du Project B</center> </body> </html>
Modifiez l'appartenance du répertoire /var/www/html et son contenu :
root@debian8:~# chown -R apache:apache /var/www/html
Modifiez le fichier /etc/resolv.conf en y ajoutant la ligne nameserver 127.0.0.1 :
[root@centos7 ~]# vi /etc/resolv.conf [root@centos7 ~]# cat /etc/resolv.conf # Generated by NetworkManager search i2tch.loc nameserver 127.0.0.1 nameserver 8.8.8.8
Testez que vous avez accès aux hôtes virtuels :
[root@centos7 ~]# lynx --dump http://www.rhelnom.com Accueil du site 1 [root@centos7 ~]# lynx --dump http://www.rhelip.com Accueil du site 2 [root@centos7 ~]# lynx --dump http://i2tch.loc Accueil du site par défaut [root@centos7 ~]# lynx --dump http://projecta.i2tch.loc Accueil du Project A [root@centos7 ~]# lynx --dump http://projectb.i2tch.loc Accueil du Project A [root@centos7 ~]# lynx --dump http://projectc.i2tch.loc Not Found The requested URL / was not found on this server.
Sous Debian 8
Hôte virtuel par nom
Sous Debian 8 la configuration des hôtes virtuels ne se fait pas de la même façon que sous RHEL / CentOS 7. Sous Debian, les hôtes virtuels sont configurés par des fichiers par hôte dans le répertoire /etc/apache2/sites-available. Ils sont activés en créant un lien symbolique dans le répertoire /etc/apache2/sites-enabled :
root@debian8:~# vi /etc/apache2/sites-available/debiannom.conf root@debian8:~# cat /etc/apache2/sites-available/debiannom.conf <VirtualHost *:80> ServerName debiannom.com ServerAlias www.debiannom.com ServerAdmin webmaster@localhost DocumentRoot /www/site1 <Directory "/www/site1"> AllowOverride None Require all granted </Directory> </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Créez un répertoire /www/site1 à la racine de votre arborescence pour héberger notre premier hôte virtuel :
root@debian8:~# mkdir -p /www/site1
Créez ensuite le fichier index.html du répertoire /www/site1:
root@debian8:~# vi /www/site1/index.html root@debian8:~# cat /www/site1/index.html <html> <head> <title>Page de Test</title> <body> <center>Accueil du site 1</center> </body> </html>
Important : Notez qu'Apache servira toujours le contenu du fichier /etc/apache2/sites-available/000-default.conf par défaut, sauf précision de la part de l'internaute.
Modifiez l'appartenance du répertoire /www et son contenu :
root@debian8:/etc/apache2/sites-enabled# chown -R www-data:www-data /www
Créez ensuite un lien symbolique dans le répertoire /etc/apache2/sites-enabled pointant vers le fichier /etc/apache2/sites-available/debiannom.conf :
root@debian8:~# cd /etc/apache2/sites-enabled/ root@debian8:/etc/apache2/sites-enabled# ln -s ../sites-available/debiannom.conf . root@debian8:/etc/apache2/sites-enabled# ls -l total 0 lrwxrwxrwx 1 root root 35 Aug 27 11:08 000-default.conf -> ../sites-available/000-default.conf lrwxrwxrwx 1 root root 33 Aug 27 18:32 debiannom.conf -> ../sites-available/debiannom.conf
Redémarrez ensuite le serveur Apache :
root@debian8:/etc/apache2/sites-enabled# systemctl restart apache2
Avant de pouvoir consulter le site virtuel, il faut renseigner votre fichier /etc/hosts :
root@debian8:/etc/apache2/sites-enabled# vi /etc/hosts root@debian8:/etc/apache2/sites-enabled# cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 debian8.i2tch.loc debian8 # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters 10.0.2.15 i2tch.loc 10.0.2.15 www.i2tch.loc 10.0.2.15 www.debiannom.com
Sauvegardez votre fichier hosts et installez le navigateur web en mode texte lynx :
root@debian8:/etc/apache2/sites-enabled# apt-get install lynx
Testez votre configuration avec lynx :
root@debian8:/etc/apache2/sites-enabled# lynx --dump http://www.debiannom.com Accueil du site 1 root@debian8:/etc/apache2/sites-enabled#
Afin de mieux comprendre les visites à notre site virtuel, nous avons besoin d'un fichier log ainsi qu'un fichier de log des erreurs. Ouvrez donc le fichier /etc/apache2/sites-available/debiannom.conf et ajoutez les deux lignes suivantes:
Customlog /www/logs/site1/debiannom.log combined Errorlog /www/logs/site1/debiannom_error.log
Vous obtiendrez une fenêtre similaire à celle-ci :
- debiannom.conf
<VirtualHost *:80> ServerName debiannom.com ServerAlias www.debiannom.com ServerAdmin webmaster@localhost DocumentRoot /www/site1 Customlog /www/logs/site1/debiannom.log combined Errorlog /www/logs/site1/debiannom_error.log <Directory "/www/site1"> AllowOverride None Require all granted </Directory> </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Créez ensuite le répertoire /www/logs/site1 :
root@debian8:/etc/apache2/sites-enabled# mkdir -p /www/logs/site1
Modifiez l'appartenance du répertoire /www/logs et son contenu :
root@debian8:/etc/apache2/sites-enabled# chown -R www-data:www-data /www/logs
Redémarrez le serveur Apache :
root@debian8:/etc/apache2/sites-enabled# systemctl restart apache2
Testez votre configuration avec lynx :
root@debian8:/etc/apache2/sites-enabled# lynx --dump http://www.debiannom.com Accueil du site 1 root@debian8:/etc/apache2/sites-enabled#
Contrôlez maintenant le contenu du répertoire /www/logs/site1. Vous devez y retrouver deux fichiers :
root@debian8:/etc/apache2/sites-enabled# ls -l /www/logs/site1/ total 4 -rw-r--r-- 1 root root 0 Aug 27 19:34 debiannom_error.log -rw-r--r-- 1 root root 131 Aug 27 19:35 debiannom.log
Ces deux fichiers debiannom_error.log et debiannom.log sont créés automatiquement par Apache.
En contrôlant le contenu du fichier /www/logs/site1/debiannom.log nous constatons que le log a été généré :
root@debian8:/etc/apache2/sites-enabled# cat /www/logs/site1/debiannom.log 10.0.2.15 - - [27/Aug/2018:19:35:07 +0100] "GET / HTTP/1.0" 200 370 "-" "Lynx/2.8.9dev.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/3.3.8"
Hôte virtuel par adresse IP
NetworkManager inclus la notion de connections ou profils permettant des configurations différentes en fonction de la localisation. Pour voir les connections actuelles, utilisez la commande nmcli c avec la sous-commande show :
Si vous constatez que vous n'avez pas de profil dans la sortie de la commande nmcli c show, ceci indique que NetworkManager ne gère pas la carte :
root@debian8:/etc/apache2/sites-enabled# cd ~ root@debian8:~# nmcli c show NAME UUID TYPE DEVICE
Dans ce cas, le fichier /etc/network/interfaces contiendra une entrée pour la carte eth0 :
root@debian8:~# cat /etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0 iface eth0 inet dhcp
Afin de permettre NetworkManager de gérer la carte malgré cette configuration, il convient d'éditer le fichier /etc/NetworkManager/NetworkManager.conf et passer la directive managed=false à managed=true :
root@debian8:~# vi /etc/NetworkManager/NetworkManager.conf root@debian8:~# cat /etc/NetworkManager/NetworkManager.conf [main] plugins=ifupdown,keyfile [ifupdown] managed=true
Il faut ensuite re-démarrer le service NetworkManager :
root@debian8:~# systemctl restart NetworkManager.service
Constatez la sortie de la commande nmcli c show :
root@debian8:~# nmcli c show NAME UUID TYPE DEVICE eth0 b88d25a0-2d19-429d-a808-d2548be81dec 802-3-ethernet eth0 Ifupdown (eth0) 681b428f-beaf-8932-dce4-687ed5bae28e 802-3-ethernet --
Créez maintenant un profil IP fixe rattaché au périphérique eth0 :
root@debian8:~# nmcli connection add con-name ip_fixe ifname eth0 type ethernet ip4 10.0.2.16/24 gw4 10.0.2.2 Connection 'ip_fixe' (0421e288-cb7c-4569-ac1f-70598a13c96f) successfully added.
Constatez sa présence :
root@debian8:~# nmcli c show NAME UUID TYPE DEVICE ip_fixe 0421e288-cb7c-4569-ac1f-70598a13c96f 802-3-ethernet -- eth0 b88d25a0-2d19-429d-a808-d2548be81dec 802-3-ethernet eth0 Ifupdown (eth0) 681b428f-beaf-8932-dce4-687ed5bae28e 802-3-ethernet --
L'étude du fichier /etc/NetworkManager/system-connections/ip_fixe démontre l'absence de directives concernant les DNS :
root@debian8:~# cat /etc/NetworkManager/system-connections/ip_fixe [connection] id=ip_fixe uuid=0421e288-cb7c-4569-ac1f-70598a13c96f interface-name=eth0 type=ethernet [ipv4] method=manual address1=10.0.2.16/24,10.0.2.2
Activez la connexion ip_fixe :
root@debian8:~# nmcli connection up ip_fixe
Ajoutez le DNS 8.8.8.8 au profil ip_fixe :
root@debian8:~# nmcli connection mod ip_fixe ipv4.dns 8.8.8.8
L'étude du fichier /etc/NetworkManager/system-connections/ip_fixe démontre que la directive concernant le serveur DNS a été ajoutée :
root@debian8:~# cat /etc/NetworkManager/system-connections/ip_fixe [connection] id=ip_fixe uuid=0421e288-cb7c-4569-ac1f-70598a13c96f interface-name=eth0 type=ethernet [ipv6] method=auto [ipv4] method=manual dns=8.8.8.8; address1=10.0.2.16/24,10.0.2.2
Afin que la modification du serveur DNS soit prise en compte, re-démarrez le service NetworkManager :
root@debian8:~# systemctl restart NetworkManager.service root@debian8:~# root@debian8:~# systemctl status NetworkManager.service ● NetworkManager.service - Network Manager Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled) Active: active (running) since Mon 2018-08-27 20:04:16 BST; 30s ago Main PID: 32570 (NetworkManager) CGroup: /system.slice/NetworkManager.service └─32570 /usr/sbin/NetworkManager --no-daemon Aug 27 20:04:16 debian8 NetworkManager[32570]: <info> Activation (eth0) Stage 5 of 5 (IPv4 Commit) started... Aug 27 20:04:16 debian8 NetworkManager[32570]: <info> (eth0): device state change: ip-config -> ip-check (reason 'none') [70 80 0] Aug 27 20:04:16 debian8 NetworkManager[32570]: <info> Activation (eth0) Stage 5 of 5 (IPv4 Commit) complete. Aug 27 20:04:16 debian8 NetworkManager[32570]: <info> Activation (eth0) Stage 5 of 5 (IPv6 Commit) started... Aug 27 20:04:16 debian8 NetworkManager[32570]: <info> Activation (eth0) Stage 5 of 5 (IPv6 Commit) complete. Aug 27 20:04:16 debian8 NetworkManager[32570]: <info> (eth0): device state change: ip-check -> secondaries (reason 'none') [80 90 0] Aug 27 20:04:16 debian8 NetworkManager[32570]: <info> (eth0): device state change: secondaries -> activated (reason 'none') [90 100 0] Aug 27 20:04:16 debian8 NetworkManager[32570]: <info> Policy set 'eth0' (eth0) as default for IPv4 routing and DNS. Aug 27 20:04:16 debian8 NetworkManager[32570]: <info> Activation (eth0) successful, device activated. Aug 27 20:04:22 debian8 NetworkManager[32570]: <info> startup complete
Vérifiez la resolution des noms :
root@debian8:~# ping www.free.fr PING www.free.fr (212.27.48.10) 56(84) bytes of data. 64 bytes from www.free.fr (212.27.48.10): icmp_seq=1 ttl=63 time=80.3 ms 64 bytes from www.free.fr (212.27.48.10): icmp_seq=2 ttl=63 time=94.8 ms 64 bytes from www.free.fr (212.27.48.10): icmp_seq=3 ttl=63 time=88.9 ms 64 bytes from www.free.fr (212.27.48.10): icmp_seq=4 ttl=63 time=107 ms ^C --- www.free.fr ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3025ms rtt min/avg/max/mdev = 80.331/92.823/107.080/9.730 ms
Avant de pouvoir consulter les sites virtuels existants, il faut modifier votre fichier /etc/hosts :
root@debian8:/etc/apache2/sites-enabled# vi /etc/hosts root@debian8:/etc/apache2/sites-enabled# cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 debian8.i2tch.loc debian8 # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters 10.0.2.16 i2tch.loc 10.0.2.16 www.i2tch.loc 10.0.2.16 www.debiannom.com
Vous allez maintenant procéder à la création d'un site ( hôte ) virtuel par adresse IP. Normalement, votre serveur serait muni de deux cartes réseaux permettant ainsi d'attribuer un site ou hôte virtuel par numéro IP. Cependant, dans le cas suivant vous allez tout simplement affecté deux numéros IP à la même carte afin de procéder aux tests. Pour faire ceci, vous devez associer une deuxième adresse IP à votre carte réseau eth0. Saisissez donc la commande suivante dans une fenêtre de console en tant que root :
root@debian8:~# ip a | grep 'inet ' inet 127.0.0.1/8 scope host lo inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 root@debian8:~# ip a add 192.168.1.99/24 dev eth0 root@debian8:~# ip a | grep 'inet ' inet 127.0.0.1/8 scope host lo inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 inet 192.168.1.99/24 scope global eth0
Créez maintenant le répertoire pour notre site2 :
root@debian8:~# mkdir /www/site2
Créez la page d'accueil :
root@debian8:~# vi /www/site2/index.html root@debian8:~# cat /www/site2/index.html <html> <body> <center>Accueil du site 2</center> </body> </html>
Créez ensuite le répertoire /www/logs/site2 :
root@debian8:~# mkdir /www/logs/site2
Modifiez l'appartenance du répertoire /www et son contenu :
root@debian8:~# chown -R www-data:www-data /www
Copiez le fichier /etc/apache2/sites-available/debiannom.conf vers /etc/apache2/sites-available/debianip.conf :
root@debian8:~# cp /etc/apache2/sites-available/debiannom.conf /etc/apache2/sites-available/debianip.conf
Editez maintenant le fichier /etc/apache2/sites-available/debianip.conf:
root@debian8:~# vi /etc/apache2/sites-available/debianip.conf root@debian8:~# cat /etc/apache2/sites-available/debianip.conf <VirtualHost 192.168.1.99:80> ServerName debianip.com ServerAlias www.debianip.com ServerAdmin webmaster@localhost DocumentRoot /www/site2 Customlog /www/logs/site2/debianip.log combined Errorlog /www/logs/site2/debianip_error.log <Directory "/www/site2"> AllowOverride None Require all granted </Directory> </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Créez le lien symbolique pour activer le site :
root@debian8:~# cd /etc/apache2/sites-enabled root@debian8:/etc/apache2/sites-enabled# ln -s ../sites-available/debianip.conf .
Éditez ensuite le fichier /etc/hosts :
root@debian8:/etc/apache2/sites-enabled# vi /etc/hosts root@debian8:/etc/apache2/sites-enabled# cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 debian8.i2tch.loc debian8 # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters 10.0.2.16 i2tch.loc 10.0.2.16 www.i2tch.loc 10.0.2.16 www.debiannom.com 192.168.1.99 www.debianip.com
Redémarrez votre serveur Apache :
root@debian8:/etc/apache2/sites-enabled# systemctl restart httpd
Testez votre configuration avec lynx :
root@debian8:/etc/apache2/sites-enabled# lynx --dump http://www.debianip.com Accueil du site 2 root@debian8:/etc/apache2/sites-enabled#
Consultez maintenant le répertoire /www/logs/site2. Vous constaterez l'apparition d'un fichier log pour le site www.debianip.com :
root@debian8:/etc/apache2/sites-enabled# ls -l /www/logs/site2/ total 4 -rw-r--r-- 1 root root 0 Aug 27 22:14 debianip_error.log -rw-r--r-- 1 root root 134 Aug 27 22:17 debianip.log root@debian8:/etc/apache2/sites-enabled# cat /www/logs/site2/debianip.log 192.168.1.99 - - [27/Aug/2018:22:17:23 +0100] "GET / HTTP/1.0" 200 311 "-" "Lynx/2.8.9dev.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/3.3.8"
Hôtes Virtuels Dynamiques avec mod_vhost_alias
Commencez par installer le paquet dnsmasq afin de fournir les services d'un serveur DNS :
root@debian8:/etc/apache2/sites-enabled# cd ~ root@debian8:~# apt-get install dnsmasq
Créez le fichier /etc/dnsmasq.d/i2tch pour indiquer à dnsmasq que le domaine i2tch.loc se trouve à l'adresse 127.0.0.1 :
root@debian8:~# vi /etc/dnsmasq.d/i2tch root@debian8:~# cat /etc/dnsmasq.d/i2tch listen-address=127.0.0.1 address=/.i2tch.loc/127.0.0.1
Re-démarrez le service dnsmasq pour prendre en compte vos modifications :
root@debian8:~# systemctl restart dnsmasq
Pour qu'apache puisse gérer les hôtes virtuels dynamiques, il faut que les modules mod_rewrite et mod_vhost_alias soient activés :
root@debian8:~# a2enmod vhost_alias Enabling module vhost_alias. To activate the new configuration, you need to run: service apache2 restart root@debian8:~# root@debian8:~# a2enmod rewrite Enabling module rewrite. To activate the new configuration, you need to run: service apache2 restart
Editez maintenant le fichier /etc/apache2/sites-available/000-default.conf :
root@debian8:~# vi /etc/apache2/sites-available/000-default.conf root@debian8:~# cat /etc/apache2/sites-available/000-default.conf <VirtualHost *:80> ServerName i2tch.loc ServerAlias *.i2tch.loc ServerAdmin webmaster@localhost VirtualDocumentRoot /var/www/html/%-3 LogLevel info ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /> Options FollowSymLinks AllowOverride All </Directory> </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Créez le fichier /var/www/html/.htaccess afin d'activer la ré-écriture des URLs :
root@debian8:~# vi /var/www/html/.htaccess root@debian8:~# cat /var/www/html/.htaccess RewriteEngine On RewriteBase /
Re-démarrez le serveur apache2 :
root@debian8:~# systemctl restart apache2
Creéz maintenant le répertoire /var/www/html/_ pour contenir le site par défaut :
root@debian8:~# mkdir /var/www/html/_
Créez la page d'accueil du site par défaut :
root@debian8:~# vi /var/www/html/_/index.html root@debian8:~# cat /var/www/html/_/index.html <html> <body> <center>Accueil du site par défaut</center> </body> </html>
Créez deux sites projecta et projectb :
root@debian8:~# mkdir /var/www/html/projecta root@debian8:~# vi /var/www/html/projecta/index.html root@debian8:~# cat /var/www/html/projecta/index.html <html> <body> <center>Accueil du Project A</center> </body> </html>
root@debian8:~# mkdir /var/www/html/projectb root@debian8:~# vi /var/www/html/projectb/index.html root@debian8:~# cat /var/www/html/projectb/index.html <html> <body> <center>Accueil du Project B</center> </body> </html>
Modifiez l'appartenance du répertoire /var/www/html et son contenu :
root@debian8:~# chown -R www-data:www-data /var/www/html
Modifiez le fichier /etc/resolv.conf en y ajoutant la ligne nameserver 127.0.0.1 :
root@debian8:~# vi /etc/resolv.conf root@debian8:~# cat /etc/resolv.conf # Generated by NetworkManager nameserver 127.0.0.1 nameserver 8.8.8.8
Testez que vous avez accès aux hôtes virtuels :
root@debian8:~# lynx --dump http://www.debiannom.com Accueil du site 1 root@debian8:~# lynx --dump http://www.debianip.com Accueil du site 2 root@debian8:~# lynx --dump http://i2tch.loc Accueil du site par défaut root@debian8:~# lynx --dump http://projecta.i2tch.loc/ Accueil du Project A root@debian8:~# lynx --dump http://projectb.i2tch.loc/ Accueil du Project B
LAB #2 - Gestion des pages personnelles avec mod_userdir
Sous RHEL / CentOS 7
Pour qu'apache puisse gérer les pages personnelles des utilisateurs enregistrées du système, il faut que le module mod_userdir soit activé dans le fichier /etc/httpd/conf.modules.d/00-base.conf :
... LoadModule userdir_module modules/mod_userdir.so ...
Afin de pouvoir tester les pages perso, ajoutez un nouveau utilisateur dénommé homepage :
[root@centos7 ~]# groupadd homepage && useradd homepage -c homepage -g homepage -d /home/homepage -s /bin/bash
Créez le répertoire /home/homepage/public_html :
[root@centos7 ~]# mkdir /home/homepage/public_html
Modifiez l'appartenance du répertoire /home/homepage :
[root@centos7 ~]# chown -R homepage:homepage /home/homepage
Ouvrez le fichier /etc/httpd/conf.d/userdir.conf. Le but de de fichier est de configurer le support des répertoires des utilisateurs dans le cas où le module mod_userdir.c est chargé :
[root@centos7 ~]# cat /etc/httpd/conf.d/userdir.conf # # UserDir: The name of the directory that is appended onto a user's home # directory if a ~user request is received. # # The path to the end user account 'public_html' directory must be # accessible to the webserver userid. This usually means that ~userid # must have permissions of 711, ~userid/public_html must have permissions # of 755, and documents contained therein must be world-readable. # Otherwise, the client will only receive a "403 Forbidden" message. # <IfModule mod_userdir.c> # # UserDir is disabled by default since it can confirm the presence # of a username on the system (depending on home directory # permissions). # UserDir disabled # # To enable requests to /~user/ to serve the user's public_html # directory, remove the "UserDir disabled" line above, and uncomment # the following line instead: # #UserDir public_html </IfModule> # # Control access to UserDir directories. The following is an example # for a site where these directories are restricted to read-only. # <Directory "/home/*/public_html"> AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS </Directory>
Modifiez ce fichier ainsi :
[root@centos7 ~]# vi /etc/httpd/conf.d/userdir.conf [root@centos7 ~]# cat /etc/httpd/conf.d/userdir.conf # # UserDir: The name of the directory that is appended onto a user's home # directory if a ~user request is received. # # The path to the end user account 'public_html' directory must be # accessible to the webserver userid. This usually means that ~userid # must have permissions of 711, ~userid/public_html must have permissions # of 755, and documents contained therein must be world-readable. # Otherwise, the client will only receive a "403 Forbidden" message. # <IfModule mod_userdir.c> UserDir public_html </IfModule> # # Control access to UserDir directories. The following is an example # for a site where these directories are restricted to read-only. # <Directory "/home/*/public_html"> AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS </Directory>
Redémarrez le service apache :
[root@centos7 ~]# systemctl restart httpd
Creéz maintenant une page d'accueil dans le répertoire /home/homepage/public_html/:
[root@centos7 ~]# vi /home/homepage/public_html/index.html [root@centos7 ~]# cat /home/homepage/public_html/index.html <html> <head> <title>Page de Test</title> <body> <center>La Page de l'utilisateur Homepage</center> </body> </html>
Modifiez les permissions sur le répertoire /home/homepage afin que l'utilisateur apache puisse avoir accès à son contenu :
[root@centos7 ~]# chmod 711 /home/homepage [root@centos7 ~]# chmod 755 /home/homepage/public_html/ [root@centos7 ~]# chmod 666 /home/homepage/public_html/index.html
Le site personnel de l'utilisateur est maintenant en ligne. Pour le tester utilisez lynx :
[root@centos7 ~]# lynx --dump http://localhost/~homepage/ La Page de l'utilisateur Homepage [root@centos7 ~]#
Sous Debian 8
Pour qu'apache puisse gérer les pages personnelles des utilisateurs enregistrées du système, il faut que le module mod_userdir soit activé :
root@debian8:~# apachectl -M | grep userdir root@debian8:~# a2enmod userdir Enabling module userdir. To activate the new configuration, you need to run: service apache2 restart root@debian8:~# apachectl -M | grep userdir userdir_module (shared) root@debian8:~# systemctl restart apache2
Afin de pouvoir tester les pages perso, ajoutez un nouveau utilisateur dénommé homepage :
root@debian8:~# groupadd homepage root@debian8:~# useradd homepage -m -c homepage -g homepage -d /home/homepage -s /bin/bash
Créez le répertoire /home/homepage/public_html :
root@debian8:~# mkdir /home/homepage/public_html
Modifiez l'appartenance du répertoire /home/homepage :
root@debian8:~# chown -R homepage:homepage /home/homepage
Consultez le fichier /etc/apache2/mods-available/userdir.conf. Le but de de fichier est de configurer le support des répertoires des utilisateurs dans le cas où le module mod_userdir.c est chargé :
<code> root@debian8:~# cat /etc/apache2/mods-available/userdir.conf <IfModule mod_userdir.c> UserDir public_html UserDir disabled root <Directory /home/*/public_html> AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec <Limit GET POST OPTIONS> Require all granted </Limit> <LimitExcept GET POST OPTIONS> Require all denied </LimitExcept> </Directory> </IfModule> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Creéz maintenant une page d'accueil dans le répertoire /home/homepage/public_html/:
root@debian8:~# vi /home/homepage/public_html/index.html root@debian8:~# cat /home/homepage/public_html/index.html <html> <head> <title>Page de Test</title> <body> <center>La Page de l'utilisateur Homepage</center> </body> </html>
Modifiez les permissions sur le répertoire /home/homepage afin que l'utilisateur www-data puisse avoir accès à son contenu :
root@debian8:~# chmod 711 /home/homepage root@debian8:~# chmod 755 /home/homepage/public_html/ root@debian8:~# chmod 666 /home/homepage/public_html/index.html
Le site personnel de l'utilisateur est maintenant en ligne. Pour le tester utilisez lynx :
root@debian8:~# lynx --dump http://localhost/~homepage/ La Page de l'utilisateur Homepage root@debian8:~#
<html> <DIV ALIGN=“CENTER”> Copyright © 2004-2018 Hugh Norris. </DIV> </html>