Apache » Historique » Version 37
Patrice Nadeau, 2017-06-03 14:33
| 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 | 29 | Patrice Nadeau | # Installation |
| 15 | 31 | Patrice Nadeau | zypper install apache2 |
| 16 | 29 | Patrice Nadeau | # Activation au démarrage |
| 17 | 5 | Patrice Nadeau | systemctl enable apache2.service |
| 18 | 1 | Patrice Nadeau | # Démarrer Apache : |
| 19 | 26 | Patrice Nadeau | systemctl start apache2.service |
| 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 | h2. Modules supplémentaires |
||
| 30 | 32 | Patrice Nadeau | > La configuration d'Apache doit être relue lors de l'activation d'un module |
| 31 | 1 | Patrice Nadeau | |
| 32 | 33 | Patrice Nadeau | La liste des modules actifs peut être listé avec |
| 33 | 32 | Patrice Nadeau | <pre><code class="bash"> |
| 34 | a2enmod -l |
||
| 35 | </code></pre> |
||
| 36 | |||
| 37 | h3. Version |
||
| 38 | 31 | Patrice Nadeau | |
| 39 | Inclut dans Apache |
||
| 40 | 1 | Patrice Nadeau | <pre><code class="bash"> |
| 41 | a2enmod mod_version |
||
| 42 | 31 | Patrice Nadeau | </code></pre> |
| 43 | |||
| 44 | h3. PHP |
||
| 45 | |||
| 46 | Support pour PHP |
||
| 47 | <pre><code class="bash"> |
||
| 48 | zypper install apache2-mod_php5 |
||
| 49 | 1 | Patrice Nadeau | a2enmod mod_php5 |
| 50 | 33 | Patrice Nadeau | </code></pre> |
| 51 | |||
| 52 | h3. Proxy |
||
| 53 | |||
| 54 | 35 | Patrice Nadeau | Redirection de serveur |
| 55 | 33 | Patrice Nadeau | <pre><code class="bash"> |
| 56 | a2enmod proxy |
||
| 57 | a2enmod proxy_http |
||
| 58 | 30 | Patrice Nadeau | </code></pre> |
| 59 | |||
| 60 | 36 | Patrice Nadeau | h2. HTTPS |
| 61 | |||
| 62 | > Self-certificate |
||
| 63 | |||
| 64 | Générer les clés |
||
| 65 | <pre><code class="bash"> |
||
| 66 | openssl req -new > new.ssl.csr |
||
| 67 | openssl rsa -in privkey.pem -out new.cert.key |
||
| 68 | openssl x509 -in new.ssl.csr -out new.cert.cert -req -signkey new.cert.key -days 365 |
||
| 69 | cp new.cert.cert /etc/ssl/certs/server.crt |
||
| 70 | cp new.cert.key /etc/ssl/private/server.key |
||
| 71 | </code></pre> |
||
| 72 | |||
| 73 | 37 | Patrice Nadeau | Modifier le fichier _/etc/apache2/default-server.conf_ |
| 74 | 36 | Patrice Nadeau | <pre><code class="php"> |
| 75 | Listen 443 |
||
| 76 | <VirtualHost *:443> |
||
| 77 | SSLEngine on |
||
| 78 | SSLCertificateFile /etc/ssl/certs/server.crt |
||
| 79 | SSLCertificateKeyFile /etc/ssl/private/server.key |
||
| 80 | </VirtualHost> |
||
| 81 | </code></pre> |
||
| 82 | |||
| 83 | 3 | Patrice Nadeau | h2. Serveurs virtuels |
| 84 | 1 | Patrice Nadeau | |
| 85 | 19 | Patrice Nadeau | Apache permet de rediriger les demandes d’accès vers |
| 86 | * différents répertoires sur le même serveur |
||
| 87 | * différents port |
||
| 88 | * un autre serveur |
||
| 89 | |||
| 90 | 17 | Patrice Nadeau | Très utile pour rediriger les requêtes à partir d'internet avec un seule adresse IP publique (NAT(Network Address Translation)). |
| 91 | |||
| 92 | |||
| 93 | 18 | Patrice Nadeau | Si le fichier _/etc/apache2/vhosts.d/vhost.conf_ n'existe pas, le créer à partir du gabarit de base |
| 94 | 17 | Patrice Nadeau | <pre><code class="bash"> |
| 95 | cd /etc/apache2/vhosts.d/ |
||
| 96 | cp vhost.template vhost.conf |
||
| 97 | </code></pre> |
||
| 98 | |||
| 99 | 8 | Patrice Nadeau | h3. Redirection vers un dossier différent. |
| 100 | 6 | Patrice Nadeau | |
| 101 | 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_ |
| 102 | 15 | Patrice Nadeau | <pre><code class="php"> |
| 103 | <VirtualHost *:80> |
||
| 104 | 16 | Patrice Nadeau | ServerName helpdesk.domain.tld |
| 105 | DocumentRoot /srv/www/htdocs/hepdesk |
||
| 106 | 15 | Patrice Nadeau | ServerAdmin admin@domain.tld |
| 107 | 16 | Patrice Nadeau | <Directory "/srv/www/htdocs/helpdesk"> |
| 108 | 25 | Patrice Nadeau | #Order allow,deny #Since Apache 2.4 |
| 109 | 22 | Patrice Nadeau | Require all granted |
| 110 | 15 | Patrice Nadeau | </Directory> |
| 111 | </VirtualHost> |
||
| 112 | |||
| 113 | <VirtualHost *:80> |
||
| 114 | ServerName wiki.domain.tld |
||
| 115 | DocumentRoot /srv/www/htdocs/wiki |
||
| 116 | ServerAdmin admin@domain.tld |
||
| 117 | <Directory "/srv/www/htdocs/wiki"> |
||
| 118 | 25 | Patrice Nadeau | #Order allow,deny # since Apache 2.4 |
| 119 | 22 | Patrice Nadeau | Require all granted |
| 120 | 1 | Patrice Nadeau | </Directory> |
| 121 | </VirtualHost> |
||
| 122 | </code></pre> |
||
| 123 | |||
| 124 | Modifier les items suivants : |
||
| 125 | * *ServerAdmin* : L'adresse de courriel de l'administrateur |
||
| 126 | 4 | Patrice Nadeau | * *ServerName* : Le FQDN(Fully Qualified Domain Name) du serveur |
| 127 | 1 | Patrice Nadeau | * *DocumentRoot* : L'emplacement des fichiers du site web |
| 128 | 7 | Patrice Nadeau | |
| 129 | h3. Redirection vers un serveur différent |
||
| 130 | |||
| 131 | 34 | Patrice Nadeau | > Les modules _proxy_ et _proxy_http_ doivent déjà être actifs |
| 132 | 11 | Patrice Nadeau | |
| 133 | 12 | Patrice Nadeau | Modifier le fichier _/etc/apache2/vhosts.d/vhost.conf_ |
| 134 | 13 | Patrice Nadeau | Ex. : On veux rediriger le service _service_ vers le serveur _server1_ |
| 135 | 14 | Patrice Nadeau | <pre><code class="php"> |
| 136 | 12 | Patrice Nadeau | <VirtualHost *:80> |
| 137 | ServerName service.domaine.com |
||
| 138 | 28 | Patrice Nadeau | ProxyPreserveHost On |
| 139 | 12 | Patrice Nadeau | ProxyPass / http://serveur1.domaine.com/ |
| 140 | ProxyPassReverse / http://serveur1.domaine.com/ |
||
| 141 | 13 | Patrice Nadeau | ServerAdmin admin@domaine.com |
| 142 | 12 | Patrice Nadeau | </VirtualHost> |
| 143 | 11 | Patrice Nadeau | |
| 144 | 12 | Patrice Nadeau | </code></pre> |
| 145 | 11 | Patrice Nadeau | |
| 146 | 7 | Patrice Nadeau | h3. Activation des changements |
| 147 | 1 | Patrice Nadeau | |
| 148 | Relire la configuration d'Apache |
||
| 149 | <pre><code class="bash"> |
||
| 150 | 27 | Patrice Nadeau | systemctl reload apache2.service |
| 151 | 1 | Patrice Nadeau | </code></pre> |
| 152 | |||
| 153 | Commandes |
||
| 154 | 10 | Patrice Nadeau | * _apache2ctl -S_ : liste les serveurs virtuels |