Apache » Historique » Version 51
Patrice Nadeau, 2017-10-02 19:24
| 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 | 50 | Patrice Nadeau | sudo zypper install apache2 |
| 16 | 29 | Patrice Nadeau | # Activation au démarrage |
| 17 | 49 | Patrice Nadeau | sudo systemctl enable apache2.service |
| 18 | 1 | Patrice Nadeau | # Démarrer Apache : |
| 19 | 49 | Patrice Nadeau | sudo systemctl start apache2.service |
| 20 | 1 | Patrice Nadeau | </code></pre> |
| 21 | |||
| 22 | Ouvrir dans le pare-feu : |
||
| 23 | <pre><code class="bash"> |
||
| 24 | 49 | Patrice Nadeau | sudo yast firewall services add service=service:apache2 zone=EXT |
| 25 | 1 | Patrice Nadeau | </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 | 51 | Patrice Nadeau | sudo 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 | 40 | Patrice Nadeau | Serveur sécurisé |
| 63 | 36 | Patrice Nadeau | |
| 64 | 44 | Patrice Nadeau | h3. Pré-requis |
| 65 | 40 | Patrice Nadeau | |
| 66 | 43 | Patrice Nadeau | Vérifier qu'Apache supporte SSL |
| 67 | <pre><code class="bash"> |
||
| 68 | a2enmod -l |
||
| 69 | </code></pre> |
||
| 70 | |||
| 71 | Si le module *ssl* n’apparaît pas, l'activer |
||
| 72 | <pre><code class="bash"> |
||
| 73 | a2enmod ssl |
||
| 74 | </code></pre> |
||
| 75 | |||
| 76 | 41 | Patrice Nadeau | h4. Self-certificate |
| 77 | 39 | Patrice Nadeau | |
| 78 | 36 | Patrice Nadeau | Générer les clés |
| 79 | <pre><code class="bash"> |
||
| 80 | openssl req -new > new.ssl.csr |
||
| 81 | openssl rsa -in privkey.pem -out new.cert.key |
||
| 82 | openssl x509 -in new.ssl.csr -out new.cert.cert -req -signkey new.cert.key -days 365 |
||
| 83 | cp new.cert.cert /etc/ssl/certs/server.crt |
||
| 84 | 1 | Patrice Nadeau | cp new.cert.key /etc/ssl/private/server.key |
| 85 | 41 | Patrice Nadeau | </code></pre> |
| 86 | |||
| 87 | 43 | Patrice Nadeau | Modifier le fichier _/etc/apache2/default-server.conf_ |
| 88 | <pre><code class="php"> |
||
| 89 | Listen 443 |
||
| 90 | <VirtualHost *:443> |
||
| 91 | SSLEngine on |
||
| 92 | SSLCertificateFile /etc/ssl/certs/server.crt |
||
| 93 | SSLCertificateKeyFile /etc/ssl/private/server.key |
||
| 94 | </VirtualHost> |
||
| 95 | </code></pre> |
||
| 96 | |||
| 97 | 46 | Patrice Nadeau | h4. Let’s Encrypt |
| 98 | |||
| 99 | https://letsencrypt.org |
||
| 100 | 37 | Patrice Nadeau | |
| 101 | 36 | Patrice Nadeau | Certificats gratuits d'une durée de 90 jours. |
| 102 | Le renouvellement automatique peut être programmé. |
||
| 103 | |||
| 104 | 47 | Patrice Nadeau | > Le certificat n'est valide que pour un serveur en particulier, contrairement à un « wildcard ». |
| 105 | 45 | Patrice Nadeau | |
| 106 | Installer le script : |
||
| 107 | 36 | Patrice Nadeau | <pre><code class="bash"> |
| 108 | wget https://dl.eff.org/certbot-auto |
||
| 109 | chmod a+x certbot-auto |
||
| 110 | 45 | Patrice Nadeau | </code></pre> |
| 111 | |||
| 112 | Lancer le script et spécifier le nom du serveur (FQDN) : |
||
| 113 | <pre><code class="bash"> |
||
| 114 | 48 | Patrice Nadeau | # New certificate |
| 115 | 36 | Patrice Nadeau | ./certbot-auto --apache certonly |
| 116 | 48 | Patrice Nadeau | # Renew all certificate |
| 117 | ./certbot-auto renew |
||
| 118 | 1 | Patrice Nadeau | </code></pre> |
| 119 | |||
| 120 | 45 | Patrice Nadeau | Modifier le fichier _/etc/apache2/default-server.conf_ (modifier _yourdomain_ par le nom du domaine approprié) : |
| 121 | 44 | Patrice Nadeau | <pre><code class="php"> |
| 122 | Listen 443 |
||
| 123 | <VirtualHost *:443> |
||
| 124 | SSLEngine on |
||
| 125 | SSLCertificateFile /etc/letsencrypt/live/yourdomain/fullchain.pem |
||
| 126 | SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain/privkey.pem |
||
| 127 | </VirtualHost> |
||
| 128 | </code></pre> |
||
| 129 | 1 | Patrice Nadeau | |
| 130 | 44 | Patrice Nadeau | h3. Mise en service |
| 131 | |||
| 132 | Relire la configuration d'Apache |
||
| 133 | 38 | Patrice Nadeau | <pre><code class="bash"> |
| 134 | systemctl reload apache2.service |
||
| 135 | </code></pre> |
||
| 136 | |||
| 137 | 3 | Patrice Nadeau | h2. Serveurs virtuels |
| 138 | 1 | Patrice Nadeau | |
| 139 | 19 | Patrice Nadeau | Apache permet de rediriger les demandes d’accès vers |
| 140 | * différents répertoires sur le même serveur |
||
| 141 | * différents port |
||
| 142 | * un autre serveur |
||
| 143 | |||
| 144 | 17 | Patrice Nadeau | Très utile pour rediriger les requêtes à partir d'internet avec un seule adresse IP publique (NAT(Network Address Translation)). |
| 145 | |||
| 146 | |||
| 147 | 18 | Patrice Nadeau | Si le fichier _/etc/apache2/vhosts.d/vhost.conf_ n'existe pas, le créer à partir du gabarit de base |
| 148 | 17 | Patrice Nadeau | <pre><code class="bash"> |
| 149 | cd /etc/apache2/vhosts.d/ |
||
| 150 | cp vhost.template vhost.conf |
||
| 151 | </code></pre> |
||
| 152 | |||
| 153 | 8 | Patrice Nadeau | h3. Redirection vers un dossier différent. |
| 154 | 6 | Patrice Nadeau | |
| 155 | 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_ |
| 156 | 15 | Patrice Nadeau | <pre><code class="php"> |
| 157 | <VirtualHost *:80> |
||
| 158 | 16 | Patrice Nadeau | ServerName helpdesk.domain.tld |
| 159 | DocumentRoot /srv/www/htdocs/hepdesk |
||
| 160 | 15 | Patrice Nadeau | ServerAdmin admin@domain.tld |
| 161 | 16 | Patrice Nadeau | <Directory "/srv/www/htdocs/helpdesk"> |
| 162 | 25 | Patrice Nadeau | #Order allow,deny #Since Apache 2.4 |
| 163 | 22 | Patrice Nadeau | Require all granted |
| 164 | 15 | Patrice Nadeau | </Directory> |
| 165 | </VirtualHost> |
||
| 166 | |||
| 167 | <VirtualHost *:80> |
||
| 168 | ServerName wiki.domain.tld |
||
| 169 | DocumentRoot /srv/www/htdocs/wiki |
||
| 170 | ServerAdmin admin@domain.tld |
||
| 171 | <Directory "/srv/www/htdocs/wiki"> |
||
| 172 | 25 | Patrice Nadeau | #Order allow,deny # since Apache 2.4 |
| 173 | 22 | Patrice Nadeau | Require all granted |
| 174 | 1 | Patrice Nadeau | </Directory> |
| 175 | </VirtualHost> |
||
| 176 | </code></pre> |
||
| 177 | |||
| 178 | Modifier les items suivants : |
||
| 179 | * *ServerAdmin* : L'adresse de courriel de l'administrateur |
||
| 180 | 4 | Patrice Nadeau | * *ServerName* : Le FQDN(Fully Qualified Domain Name) du serveur |
| 181 | 1 | Patrice Nadeau | * *DocumentRoot* : L'emplacement des fichiers du site web |
| 182 | 7 | Patrice Nadeau | |
| 183 | h3. Redirection vers un serveur différent |
||
| 184 | |||
| 185 | 34 | Patrice Nadeau | > Les modules _proxy_ et _proxy_http_ doivent déjà être actifs |
| 186 | 11 | Patrice Nadeau | |
| 187 | 12 | Patrice Nadeau | Modifier le fichier _/etc/apache2/vhosts.d/vhost.conf_ |
| 188 | 13 | Patrice Nadeau | Ex. : On veux rediriger le service _service_ vers le serveur _server1_ |
| 189 | 14 | Patrice Nadeau | <pre><code class="php"> |
| 190 | 12 | Patrice Nadeau | <VirtualHost *:80> |
| 191 | ServerName service.domaine.com |
||
| 192 | 28 | Patrice Nadeau | ProxyPreserveHost On |
| 193 | 12 | Patrice Nadeau | ProxyPass / http://serveur1.domaine.com/ |
| 194 | ProxyPassReverse / http://serveur1.domaine.com/ |
||
| 195 | 13 | Patrice Nadeau | ServerAdmin admin@domaine.com |
| 196 | 12 | Patrice Nadeau | </VirtualHost> |
| 197 | 11 | Patrice Nadeau | |
| 198 | 12 | Patrice Nadeau | </code></pre> |
| 199 | 11 | Patrice Nadeau | |
| 200 | 7 | Patrice Nadeau | h3. Activation des changements |
| 201 | 1 | Patrice Nadeau | |
| 202 | Relire la configuration d'Apache |
||
| 203 | <pre><code class="bash"> |
||
| 204 | 27 | Patrice Nadeau | systemctl reload apache2.service |
| 205 | 1 | Patrice Nadeau | </code></pre> |
| 206 | |||
| 207 | Commandes |
||
| 208 | 10 | Patrice Nadeau | * _apache2ctl -S_ : liste les serveurs virtuels |