Ceci est une ancienne révision du document !


Serveur Web

Quelle que soit le but de votre serveur, un service web est très souvent indispensable.

Cette page a pour but de décrire l'installation et la configuration de Apache2 avec PHP.

Installation

Sous debian, il suffit d'ajouter les paquets :

  • apache2
  • PHP5

Apache est installé en mode préfork car le mode threaded n'est pas compatible php.

Configuration

La configuration d'Apache2 est définie par le fichier /etc/apache2/apache2.conf. C'est un fichier à plat mais il inclue d'autres fichiers grâce à la commande Include :

  • /etc/apache2/apache2.conf
  • /etc/apache2/httpd.conf
  • /etc/apache2/conf.d/
  • /etc/apache2/sites-enables
  • /etc/apache2/mods-enables

La configuration classique d'Apache2 est réalisée en créant un ou plusieurs fichiers personnalisés dans le dossier /etc/apache2/sites-available/ et en le(s) activant.

Pour activer ou désactiver les sites, les commandes sont :

  • a2ensite
  • a2dissite

De même, l'activation des modules est réalisée avec :

  • a2enmod
  • a2dismod

Par exemple, pour désactiver la configuration par défaut :

bender:/etc/apache2/sites-available# a2dissite default
Site default disabled; run /etc/init.d/apache2 reload to fully disable.
bender:/etc/apache2/sites-available#

Configuration d'Apache

Configuration de l'HTTPS

Cette partie décrit l'activation de l'HTTPS dans Apache2.

Création du certificat

Pour générer le certificat, voir OpenSSL.

Copier ensuite la clé privée ainsi que le certificat dans un fichier pem et le placer par exemple dans /etc/apache2/ssl/.

Ouverture des ports

Afin d'activer l'HTTPS, il faut que apache écoute le port 443. Pour cela il suffit de l'ajouter au fichier /etc/apache2/ports.conf :

Listen 80
Listen 443

Activation du module

Il faut ensuite activer le module ssl :

bender:/etc/apache2# a2enmod ssl
Module ssl installed; run /etc/init.d/apache2 force-reload to enable.
bender:/etc/apache2# /etc/init.d/apache2 force-reload
Forcing reload of web server (apache2)... waiting .
bender:/etc/apache2#

Configuration du ssl

Pour finir, il faut configurer un virtual host avec le moteur SSL activé.

Exemple de configuration :

NameVirtualHost *:443
<VirtualHost *:443>
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/mat.homeftp.org.pem

        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
                # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                RedirectMatch ^/$ /apache2-default/
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

Voici les principales directives pour le module SSL :

SSLEngine

Lien http://httpd.apache.org/docs/2.2/mod/mod_ssl.html#sslengine
DescriptionActive ou désactive me moteur SSL
Syntaxe SSLEngine on|off|optional
Contexte server config, virtual host

SSLCertificateFile

Lien http://httpd.apache.org/docs/2.2/mod/mod_ssl.html#sslcertificatefile
DescriptionIndique le fichier contenant la clé et le certificat
Syntaxe SSLCertificateKeyFile file-path
Contexte server config, virtual host

Authentification LDAP

Ce paragraphe décrit comment configurer l'authentification LDAP dans Apache2.

Installation

Pour l'installation d'un serveur LDAP, voir OpenLDAP.

L'authentification LDAP d'Apache2 est réalisée par le module authnz_ldap. Son activation se fait de la façon suivante :

bender:/etc/apache2# a2enmod authnz_ldap
Enabling ldap as a dependency
Module ldap installed; run /etc/init.d/apache2 force-reload to enable.
Module authnz_ldap installed; run /etc/init.d/apache2 force-reload to enable.
bender:/etc/apache2#

Configuration

Voici un exemple d'authentification LDAP :

<Directory /home/ssl>
     AuthType basic
     AuthName "private area"
     AuthBasicProvider ldap
     AuthLDAPURL ldap://127.0.0.1/dc=matthieu,dc=bouthors,dc=org?cn?sub?(objectClass=*)
     AuthLDAPBindDN cn=apache,ou=services,dc=matthieu,dc=bouthors,dc=org
     AuthLDAPBindPassword ***
     AuthzLDAPAuthoritative off
     require ldap-group cn=web,ou=groups,dc=matthieu,dc=bouthors,dc=org
</Directory>

Les principales directives à utiliser pour authentifier les utilisateurs en LDAP sont decrite ci-dessous.

AuthType

Lien http://httpd.apache.org/docs/2.2/mod/core.html#authtype
DescriptionDéfinit le type d'authentification
Syntaxe AuthType Basic|Digest
Contexte directory, .htaccess

AuthName

Lien http://httpd.apache.org/docs/2.2/mod/core.html#authname
DescriptionNom du royaume présenté à l'utilisateur
Syntaxe AuthName auth-domain
Contexte directory, .htaccess

AuthBasicProvider

Lien http://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html#authbasicprovider
DescriptionIndique le moteur d'authentification pour cette URL
Syntaxe AuthBasicProvider provider-name [provider-name] ...
Contexte directory, .htaccess

AuthLDAPURL

Lien http://httpd.apache.org/docs/2.2/mod/mod_authnz_ldap.html#authldapurl
DescriptionDéfinit les paramètres de recherche LDAP
Syntaxe AuthLDAPUrl ldap://host:port/basedn?attribute?scope?filter [NONE|SSL|TLS|STARTTLS]
Contexte directory, .htaccess

AuthLDAPBindDN

Lien http://httpd.apache.org/docs/2.2/mod/mod_authnz_ldap.html#authldapbinddn
DescriptionDéfinit le compte de service pour se connecter au LDAP (lorsque l'authentification anonyme est impossible).
Syntaxe AuthLDAPBindDN distinguished-name
Contexte directory, .htaccess

AuthLDAPBindPassword

Lien http://httpd.apache.org/docs/2.2/mod/mod_authnz_ldap.html#authldapbindpassword
DescriptionDéfinit le mot de passe du compte de service
Syntaxe AuthLDAPBindPassword password
Contexte directory, .htaccess

AuthzLDAPAuthoritative

Lien http://httpd.apache.org/docs/2.2/mod/mod_authnz_ldap.html#authzldapauthoritative
DescriptionPermet de contrôler si d'autre module d'authentification peuvent authentifier l'utilisateur en cas d'utilisateur introuvable dans le LDAP.
Syntaxe AuthzLDAPAuthoritative on|off
Contexte directory, .htaccess

Require

Lien http://httpd.apache.org/docs/2.2/fr/mod/core.html#require
DescriptionDéfinit quelle personne authentifiée peut accèder à ce répertoire
Syntaxe Require entity-name [entity-name] …
Contexte directory, .htaccess

Exemples :

  • N'importe quel utilisateur valide :
require valid-user
  • L'utilisateur matthieu :
require matthieu
  • Le groupe “web” :
require ldap-group cn=web,ou=groups,dc=matthieu,dc=bouthors,dc=org

Authentification MySQL

Attention : la méthode décrite ci dessous ne fonctionne plus avec les dernières version de apache. En effet le module utilisé n'est plus maintenu.

Installation

Pour l'installation de Mysql, voir Mysql.
Pour construire la base de données contenant les utilisateurs, voir Authentification sur une base SQL.

Le paquet suivant est nécessaire :

  • libapache2-auth-mysql

Une fois installé, il suffit d'activer le module avec la commande suivante :

a2enmod auth_mysql

Configuration

Voici un exemple de configuration avec l'authentification Mysql.

Pour le descriptif des directives, voir http://www.diegonet.com/support/mod_auth_mysql.shtml

# configuration authentification mysql (auth mysql)
Auth_MySQL_Info localhost apache *********
Auth_MySQL_General_DB users

        <Directory />
                AllowOverride None
       
                Auth_MySQL_Password_Table users
                Auth_MySQL_Group_Table groupes_apache
                Auth_MySQL_Username_Field login
                Auth_MySQL_Password_Field password
                Auth_MySQL_Group_Field groupe
                Auth_MySQL_Empty_Passwords off
                Auth_MySQL_Encryption_Types Crypt
                Auth_MySQL_Authoritative on
                Auth_MySQL on

                AuthType Basic
                AuthName Extranet_matthieu.bouthors.org
                Require group admin
                Order Deny,Allow
                Deny from All
        </Directory>

        <Directory /home/ssl>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
                Require valid-user
        </Directory>

Encodage des caractères spéciaux

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

Configuration de PHP

Dans /etc/php5/apache2/php.ini configurer la taille maximum d'upload autorisé, par exemple :

upload_max_filesize = 15M

Backup

  • /etc/apache2/
  • /var/log/apache2/
  • /etc/logrotate.d/apache2
  • /etc/php5/apache2/php.ini
  • /var/www/

Links

linux/serveur_web.1319058930.txt.gz · Dernière modification: 2011/10/19 23:15 par matthieu
Recent changes RSS feed Debian Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki