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