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