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