Objectifs :
Gérer Plusieurs adresses certaines pointant vers le même répertoire d'autre pointant vers des répertoires différents


Pour ajouter un site sur votre Apache il faut faire comme suit :

  1. Allez dans /etc/apache2/sites-available
  2. Tapez "sudo vim monSiteConf"
    1. Il faut être root pour éditer et enregistrer une conf Apache, d'où le sudo
  3. Saisissez une config dans votre fichier et enregistrez-la
  4. ensuite tapez : sudo a2ensite monSiteConf
    1. Ce qui pour resultat d'ajouter un lien symbolique dans sites-enabled vers votre fichier de conf
    2. Pour enlever un site il faut faire a2dissite monSiteConf (en étant placé dans sites-available)
    3. Pensez à redémarrer Apache en faisant : sudo /etc/init.d/apache2 restart
    4. Quand vous redémarrez Apache, vous ne devez pas obtenir de message d'erreur...un simple "OK" doit s'affiche :)
  5. tapez ça : sudo vim /etc/hosts
    1. et rajoutez ça : 127.0.0.1 AdresseDuSite



Voici mes exemples de conf Apache :

<VirtualHost *:80>
        ServerAdmin admin@localhost
        DocumentRoot "/home/mrjay/workspace/Portail_branche_2_1"
        ServerName xxxxx2
        ServerAlias xxxx1
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin admin@localhost
        DocumentRoot "/home/mrjay/workspace/Portail_branche_2_1"
        ServerName xxxxx1
        ServerAlias xxxxx2
        SSLEngine On
        SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
        SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>



<VirtualHost *:80>
        ServerAdmin admin@localhost
        DocumentRoot "/home/mrjay/workspace/Portail_trunk"
        ServerName xxxxx1
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin admin@localhost
        DocumentRoot "/home/mrjay/workspace/Portail_trunk"
        ServerName xxxxx2
        SSLEngine On
        SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
        SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>



Dans /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
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
    # If you add NameVirtualHost *:443 here, you will also have to change
    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
    # to <VirtualHost *:443>
    # Server Name Indication for SSL named virtual hosts is currently not
    # supported by MSIE on Windows XP.
    Listen 443
    NameVirtualHost *:443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>



Dans /etc/hosts :

127.0.0.1       xxxxxxx1
127.0.0.1      xxxxxx2
127.0.0.1       xxxxxxxx3
127.0.0.1       xxxxxxxxx4