Apache » Historique » Version 27
Patrice Nadeau, 2015-09-05 09:44
| 1 | 3 | Patrice Nadeau | h1. Apache |
|---|---|---|---|
| 2 | 1 | Patrice Nadeau | |
| 3 | Serveur de page Web |
||
| 4 | |||
| 5 | 21 | Patrice Nadeau | > Version 2.4 |
| 6 | |||
| 7 | 1 | Patrice Nadeau | --- |
| 8 | |||
| 9 | {{toc}} |
||
| 10 | |||
| 11 | 3 | Patrice Nadeau | h2. Installation |
| 12 | 1 | Patrice Nadeau | |
| 13 | <pre><code class="bash"> |
||
| 14 | zypper install apache2 apache2-mod_php5 |
||
| 15 | 5 | Patrice Nadeau | systemctl enable apache2.service |
| 16 | 1 | Patrice Nadeau | # Démarrer Apache : |
| 17 | systemctl start apache2.service |
||
| 18 | 26 | Patrice Nadeau | # Active le module mod_php5 |
| 19 | a2enmod mod_php5 |
||
| 20 | 1 | Patrice Nadeau | </code></pre> |
| 21 | |||
| 22 | Ouvrir dans le pare-feu : |
||
| 23 | <pre><code class="bash"> |
||
| 24 | yast firewall services add service=service:apache2 zone=EXT |
||
| 25 | </code></pre> |
||
| 26 | |||
| 27 | L’emplacement des fichier du serveur est _/srv/www/htdocs_. |
||
| 28 | |||
| 29 | 3 | Patrice Nadeau | h2. Serveurs virtuels |
| 30 | 1 | Patrice Nadeau | |
| 31 | 19 | Patrice Nadeau | Apache permet de rediriger les demandes d’accès vers |
| 32 | * différents répertoires sur le même serveur |
||
| 33 | * différents port |
||
| 34 | * un autre serveur |
||
| 35 | |||
| 36 | 17 | Patrice Nadeau | Très utile pour rediriger les requêtes à partir d'internet avec un seule adresse IP publique (NAT(Network Address Translation)). |
| 37 | |||
| 38 | |||
| 39 | 18 | Patrice Nadeau | Si le fichier _/etc/apache2/vhosts.d/vhost.conf_ n'existe pas, le créer à partir du gabarit de base |
| 40 | 17 | Patrice Nadeau | <pre><code class="bash"> |
| 41 | cd /etc/apache2/vhosts.d/ |
||
| 42 | cp vhost.template vhost.conf |
||
| 43 | </code></pre> |
||
| 44 | |||
| 45 | 8 | Patrice Nadeau | h3. Redirection vers un dossier différent. |
| 46 | 6 | Patrice Nadeau | |
| 47 | 16 | Patrice Nadeau | Ex. : On veux diriger _helpdesk.domain.tld_ vers le dossier _/srv/www/htdocs/helpdesk_ et _wiki.domain.tld_ vers le dossier _/srv/www/htdocs/wiki_ |
| 48 | 15 | Patrice Nadeau | <pre><code class="php"> |
| 49 | <VirtualHost *:80> |
||
| 50 | 16 | Patrice Nadeau | ServerName helpdesk.domain.tld |
| 51 | DocumentRoot /srv/www/htdocs/hepdesk |
||
| 52 | 15 | Patrice Nadeau | ServerAdmin admin@domain.tld |
| 53 | 16 | Patrice Nadeau | <Directory "/srv/www/htdocs/helpdesk"> |
| 54 | 25 | Patrice Nadeau | #Order allow,deny #Since Apache 2.4 |
| 55 | 22 | Patrice Nadeau | Require all granted |
| 56 | 15 | Patrice Nadeau | </Directory> |
| 57 | </VirtualHost> |
||
| 58 | |||
| 59 | <VirtualHost *:80> |
||
| 60 | ServerName wiki.domain.tld |
||
| 61 | DocumentRoot /srv/www/htdocs/wiki |
||
| 62 | ServerAdmin admin@domain.tld |
||
| 63 | <Directory "/srv/www/htdocs/wiki"> |
||
| 64 | 25 | Patrice Nadeau | #Order allow,deny # since Apache 2.4 |
| 65 | 22 | Patrice Nadeau | Require all granted |
| 66 | 1 | Patrice Nadeau | </Directory> |
| 67 | </VirtualHost> |
||
| 68 | </code></pre> |
||
| 69 | |||
| 70 | Modifier les items suivants : |
||
| 71 | * *ServerAdmin* : L'adresse de courriel de l'administrateur |
||
| 72 | 4 | Patrice Nadeau | * *ServerName* : Le FQDN(Fully Qualified Domain Name) du serveur |
| 73 | 1 | Patrice Nadeau | * *DocumentRoot* : L'emplacement des fichiers du site web |
| 74 | 7 | Patrice Nadeau | |
| 75 | h3. Redirection vers un serveur différent |
||
| 76 | |||
| 77 | 9 | Patrice Nadeau | Les modules _proxy_ et _proxy_http_ doivent être installés et actifs |
| 78 | |||
| 79 | Vérification de la liste des modules Apache |
||
| 80 | <pre><code class="bash"> |
||
| 81 | a2enmod -l |
||
| 82 | </code></pre> |
||
| 83 | |||
| 84 | 20 | Patrice Nadeau | Activation des modules s'il ne sont pas déjà actifs |
| 85 | 11 | Patrice Nadeau | <pre><code class="bash"> |
| 86 | 24 | Patrice Nadeau | a2enmod proxy |
| 87 | a2enmod proxy_http |
||
| 88 | 11 | Patrice Nadeau | </code></pre> |
| 89 | |||
| 90 | 12 | Patrice Nadeau | Modifier le fichier _/etc/apache2/vhosts.d/vhost.conf_ |
| 91 | 13 | Patrice Nadeau | Ex. : On veux rediriger le service _service_ vers le serveur _server1_ |
| 92 | 14 | Patrice Nadeau | <pre><code class="php"> |
| 93 | 12 | Patrice Nadeau | <VirtualHost *:80> |
| 94 | ServerName service.domaine.com |
||
| 95 | ProxyPass / http://serveur1.domaine.com/ |
||
| 96 | ProxyPassReverse / http://serveur1.domaine.com/ |
||
| 97 | 13 | Patrice Nadeau | ServerAdmin admin@domaine.com |
| 98 | 12 | Patrice Nadeau | </VirtualHost> |
| 99 | 11 | Patrice Nadeau | |
| 100 | 12 | Patrice Nadeau | </code></pre> |
| 101 | 11 | Patrice Nadeau | |
| 102 | 7 | Patrice Nadeau | h3. Activation des changements |
| 103 | 1 | Patrice Nadeau | |
| 104 | Relire la configuration d'Apache |
||
| 105 | <pre><code class="bash"> |
||
| 106 | 27 | Patrice Nadeau | systemctl reload apache2.service |
| 107 | 1 | Patrice Nadeau | </code></pre> |
| 108 | |||
| 109 | Commandes |
||
| 110 | 10 | Patrice Nadeau | * _apache2ctl -S_ : liste les serveurs virtuels |