Projet

Général

Profil

Apache » Historique » Version 45

Patrice Nadeau, 2017-06-03 15:31

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 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 36 Patrice Nadeau
h4. letsencrypt.org
98 37 Patrice Nadeau
99 36 Patrice Nadeau
Certificats gratuits d'une durée de 90 jours.
100
Le renouvellement automatique peut être programmé.
101
102 45 Patrice Nadeau
> Le certificat n'est valide que pour le serveur, contrairement à un « wildcard ».
103
104
Installer le script :
105 36 Patrice Nadeau
<pre><code class="bash">
106
wget https://dl.eff.org/certbot-auto
107
chmod a+x certbot-auto
108 45 Patrice Nadeau
</code></pre>
109
110
Lancer le script et spécifier le nom du serveur (FQDN) : 
111
<pre><code class="bash">
112 36 Patrice Nadeau
./certbot-auto --apache certonly
113 1 Patrice Nadeau
</code></pre>
114
115 45 Patrice Nadeau
Modifier le fichier _/etc/apache2/default-server.conf_ (modifier _yourdomain_ par le nom du domaine approprié) :
116 44 Patrice Nadeau
<pre><code class="php">
117
Listen 443
118
<VirtualHost *:443>
119
    SSLEngine on
120
    SSLCertificateFile /etc/letsencrypt/live/yourdomain/fullchain.pem
121
    SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain/privkey.pem
122
</VirtualHost>
123
</code></pre>
124 1 Patrice Nadeau
125 44 Patrice Nadeau
h3. Mise en service
126
127
Relire la configuration d'Apache
128 38 Patrice Nadeau
<pre><code class="bash">
129
systemctl reload apache2.service
130
</code></pre>
131
132 3 Patrice Nadeau
h2. Serveurs virtuels
133 1 Patrice Nadeau
134 19 Patrice Nadeau
Apache permet de rediriger les demandes d’accès vers 
135
* différents répertoires sur le même serveur 
136
* différents port
137
* un autre serveur
138
139 17 Patrice Nadeau
Très utile pour rediriger les requêtes à partir d'internet avec un seule adresse IP publique (NAT(Network Address Translation)).
140
141
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 17 Patrice Nadeau
<pre><code class="bash">
144
cd /etc/apache2/vhosts.d/
145
cp vhost.template vhost.conf
146
</code></pre>
147
148 8 Patrice Nadeau
h3. Redirection vers un dossier différent.
149 6 Patrice Nadeau
150 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_
151 15 Patrice Nadeau
<pre><code class="php">
152
<VirtualHost *:80>
153 16 Patrice Nadeau
        ServerName helpdesk.domain.tld
154
        DocumentRoot /srv/www/htdocs/hepdesk
155 15 Patrice Nadeau
        ServerAdmin admin@domain.tld
156 16 Patrice Nadeau
        <Directory "/srv/www/htdocs/helpdesk">
157 25 Patrice Nadeau
                #Order allow,deny #Since Apache 2.4
158 22 Patrice Nadeau
                Require all granted
159 15 Patrice Nadeau
         </Directory>
160
</VirtualHost>
161
162
<VirtualHost *:80>
163
        ServerName wiki.domain.tld
164
        DocumentRoot /srv/www/htdocs/wiki
165
        ServerAdmin admin@domain.tld
166
        <Directory "/srv/www/htdocs/wiki">
167 25 Patrice Nadeau
                #Order allow,deny # since Apache 2.4
168 22 Patrice Nadeau
                Require all granted
169 1 Patrice Nadeau
         </Directory>
170
</VirtualHost>
171
</code></pre>
172
173
Modifier les items suivants :
174
* *ServerAdmin* : L'adresse de courriel de l'administrateur
175 4 Patrice Nadeau
* *ServerName* : Le FQDN(Fully Qualified Domain Name) du serveur
176 1 Patrice Nadeau
* *DocumentRoot* : L'emplacement des fichiers du site web
177 7 Patrice Nadeau
178
h3. Redirection vers un serveur différent
179
180 34 Patrice Nadeau
> Les modules _proxy_ et _proxy_http_ doivent déjà être actifs
181 11 Patrice Nadeau
182 12 Patrice Nadeau
Modifier le fichier _/etc/apache2/vhosts.d/vhost.conf_ 
183 13 Patrice Nadeau
Ex. : On veux rediriger le service _service_ vers le serveur _server1_
184 14 Patrice Nadeau
<pre><code class="php">
185 12 Patrice Nadeau
<VirtualHost *:80>
186
        ServerName service.domaine.com
187 28 Patrice Nadeau
        ProxyPreserveHost On
188 12 Patrice Nadeau
        ProxyPass / http://serveur1.domaine.com/
189
        ProxyPassReverse / http://serveur1.domaine.com/
190 13 Patrice Nadeau
        ServerAdmin admin@domaine.com
191 12 Patrice Nadeau
</VirtualHost>
192 11 Patrice Nadeau
193 12 Patrice Nadeau
</code></pre>
194 11 Patrice Nadeau
195 7 Patrice Nadeau
h3. Activation des changements
196 1 Patrice Nadeau
197
Relire la configuration d'Apache
198
<pre><code class="bash">
199 27 Patrice Nadeau
systemctl reload apache2.service
200 1 Patrice Nadeau
</code></pre>
201
202
Commandes
203 10 Patrice Nadeau
* _apache2ctl -S_ : liste les serveurs virtuels