This is an old revision of the document!
This page describe how to configure a website with Apache.
A configuration file for Apache use a structure, for example :
<VirtualHost *:80> Servername www.bouthors.fr ServerAdmin matthieu@bouthors.fr DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all RedirectMatch ^/$ /wiki/ </Directory> </VirtualHost>
Is this example, the tags are VirtualHost and Directory, and each section contains several options like “Servername”, “DocumentRoot”, “Options”, “allow”, …
Common tags are :
The first step is to link the file system to an url path with one of the following way :
DocumentRoot /var/www
Alias /wiki /opt/dokuwiki
Then, the requests have to be autorized with the following options:
Complete example :
Alias /wiki /opt/dokuwiki <Directory /opt/dokuwiki> allow from all Order deny,allow </Directory>
Apache also allows additional parameters with “option” which can have several values :
Example with symbolic link authorization :
Alias /wiki /opt/dokuwiki <Directory /opt/dokuwiki> Options FollowSymLinks allow from all Order deny,allow </Directory>
It is possible to use ”+ and ”-” to define modification from inherited options. For example to add directory listing to a subfolder (without removing other options) :
<Directory /opt/dokuwiki/share> Options +Indexes </Directory>
Finally, it is possible to change the options with ”.htaccess” files located directly on the file system. To allow the use of ”.htaccess”, the option “AllowOverride” must be defined. For example :
Alias /wiki /opt/dokuwiki <Directory /opt/dokuwiki/> Options +FollowSymLinks AllowOverride All order allow,deny allow from all </Directory>
.htaccess example which deny all access to the folder :
order allow,deny deny from all
Note : it is possible to apply options based on url path instead of file system with the tag <Location> instead of <Directory>.
It is possible to customize the server with the following options :
Example :
ServerAdmin matthieu@bouthors.fr
Apache has several useful features :
L'hébergement local de plusieurs site se fait grâce aux options suivantes :
Par exemple pour héberger www.bouthors.fr et web3.bouthors.fr sur le même apache avec deux configurations différentes :
<VirtualHost *:80> ServerName www.bouthors.fr ServerAlias ipv6.bouthors.fr DocumentRoot /var/www ... </VirtualHost> <VirtualHost *:80> ServerName web3.bouthors.fr DocumentRoot /var/www ... </VirtualHost>
Les redirections sont très utilisées, elles permettent d'indiquer à l'utilisateur de faire sa requête auprès d'une autre url.
Les commandes utilisées sont :
Exemple de redirection de la racine d'un serveur web :
<Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all RedirectMatch ^/$ /wiki/ </Directory>
Exemple de redirection inconditionnelle par défaut :
<VirtualHost *:80> RedirectMatch 301 ^/(.*) http://www.bouthors.fr/$1 </VirtualHost>
Apache peut également agir en tant que reverse proxy et transmettre la requête à un autre serveur web. Le module mod-proxy est alors utilisé.
Il faut dans un premier temps activer mod-proxy :
# a2enmod proxy_http Considering dependency proxy for proxy_http: Enabling module proxy. Enabling module proxy_http. Run '/etc/init.d/apache2 restart' to activate new configuration! # /etc/init.d/apache2 restart
Puis utiliser la directive ProxyPass. Par exemple rediriger le répertoire /wiki vers le serveur web4 :
ProxyPass /wiki/ http://web4.bouthors.fr/wiki/
Include est utilisé pour insérer un autre fichier.
Exemple (à la fin de apache2.conf) :
# Include generic snippets of statements Include conf.d/ # Include the virtual host configurations: Include sites-enabled/
Dans /etc/php5/apache2/php.ini configurer la taille maximum d'upload autorisé, par exemple :
upload_max_filesize = 15M
Il est également nécessaire de modifier la taille des posts :
post_max_size = 8M
Dans les cas ou il faut beaucoup de mémoire, modifier memory_limit :
memory_limit = 128M
Les logs peuvent être contrôlées de différentes façons, voici quelques paramètres fréquents :
Exemple :
ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined
Le fichier /etc/apache2/conf.d/charset définit le Content-Type renvoyé par Apache.
Par défaut, il est en UTF8 :
AddDefaultCharset UTF-8
Pour configurer le serveur en ISO, il faut indiquer :
AddDefaultCharset ISO-8859-15