Projet

Général

Profil

Apache » Historique » Version 40

Patrice Nadeau, 2017-06-03 14:41

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 1 Patrice Nadeau
h3. SSL
65 40 Patrice Nadeau
66
> Self-certificate
67 39 Patrice Nadeau
68 36 Patrice Nadeau
Générer les clés
69
<pre><code class="bash">
70
openssl req -new > new.ssl.csr
71
openssl rsa -in privkey.pem -out new.cert.key
72
openssl x509 -in new.ssl.csr -out new.cert.cert -req -signkey new.cert.key -days 365
73
cp new.cert.cert /etc/ssl/certs/server.crt
74
cp new.cert.key /etc/ssl/private/server.key
75 39 Patrice Nadeau
</code></pre>
76
77
h3. Apache
78
79
Vérifier qu'Apache supporte SSL
80
<pre><code class="bash">
81
a2enmod -l
82
</code></pre>
83
84
Si le module *ssl* n’apparaît pas, l'activer
85
<pre><code class="bash">
86
a2enmod ssl
87 36 Patrice Nadeau
</code></pre>
88
89 37 Patrice Nadeau
Modifier le fichier _/etc/apache2/default-server.conf_
90 36 Patrice Nadeau
<pre><code class="php">
91
Listen 443
92
<VirtualHost *:443>
93
    SSLEngine on
94
    SSLCertificateFile /etc/ssl/certs/server.crt
95
    SSLCertificateKeyFile /etc/ssl/private/server.key
96
</VirtualHost>
97
</code></pre>
98
99 38 Patrice Nadeau
Relire la configuration d'Apache
100
<pre><code class="bash">
101
systemctl reload apache2.service
102
</code></pre>
103
104 3 Patrice Nadeau
h2. Serveurs virtuels
105 1 Patrice Nadeau
106 19 Patrice Nadeau
Apache permet de rediriger les demandes d’accès vers 
107
* différents répertoires sur le même serveur 
108
* différents port
109
* un autre serveur
110
111 17 Patrice Nadeau
Très utile pour rediriger les requêtes à partir d'internet avec un seule adresse IP publique (NAT(Network Address Translation)).
112
113
114 18 Patrice Nadeau
Si le fichier _/etc/apache2/vhosts.d/vhost.conf_ n'existe pas, le créer à partir du gabarit de base
115 17 Patrice Nadeau
<pre><code class="bash">
116
cd /etc/apache2/vhosts.d/
117
cp vhost.template vhost.conf
118
</code></pre>
119
120 8 Patrice Nadeau
h3. Redirection vers un dossier différent.
121 6 Patrice Nadeau
122 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_
123 15 Patrice Nadeau
<pre><code class="php">
124
<VirtualHost *:80>
125 16 Patrice Nadeau
        ServerName helpdesk.domain.tld
126
        DocumentRoot /srv/www/htdocs/hepdesk
127 15 Patrice Nadeau
        ServerAdmin admin@domain.tld
128 16 Patrice Nadeau
        <Directory "/srv/www/htdocs/helpdesk">
129 25 Patrice Nadeau
                #Order allow,deny #Since Apache 2.4
130 22 Patrice Nadeau
                Require all granted
131 15 Patrice Nadeau
         </Directory>
132
</VirtualHost>
133
134
<VirtualHost *:80>
135
        ServerName wiki.domain.tld
136
        DocumentRoot /srv/www/htdocs/wiki
137
        ServerAdmin admin@domain.tld
138
        <Directory "/srv/www/htdocs/wiki">
139 25 Patrice Nadeau
                #Order allow,deny # since Apache 2.4
140 22 Patrice Nadeau
                Require all granted
141 1 Patrice Nadeau
         </Directory>
142
</VirtualHost>
143
</code></pre>
144
145
Modifier les items suivants :
146
* *ServerAdmin* : L'adresse de courriel de l'administrateur
147 4 Patrice Nadeau
* *ServerName* : Le FQDN(Fully Qualified Domain Name) du serveur
148 1 Patrice Nadeau
* *DocumentRoot* : L'emplacement des fichiers du site web
149 7 Patrice Nadeau
150
h3. Redirection vers un serveur différent
151
152 34 Patrice Nadeau
> Les modules _proxy_ et _proxy_http_ doivent déjà être actifs
153 11 Patrice Nadeau
154 12 Patrice Nadeau
Modifier le fichier _/etc/apache2/vhosts.d/vhost.conf_ 
155 13 Patrice Nadeau
Ex. : On veux rediriger le service _service_ vers le serveur _server1_
156 14 Patrice Nadeau
<pre><code class="php">
157 12 Patrice Nadeau
<VirtualHost *:80>
158
        ServerName service.domaine.com
159 28 Patrice Nadeau
        ProxyPreserveHost On
160 12 Patrice Nadeau
        ProxyPass / http://serveur1.domaine.com/
161
        ProxyPassReverse / http://serveur1.domaine.com/
162 13 Patrice Nadeau
        ServerAdmin admin@domaine.com
163 12 Patrice Nadeau
</VirtualHost>
164 11 Patrice Nadeau
165 12 Patrice Nadeau
</code></pre>
166 11 Patrice Nadeau
167 7 Patrice Nadeau
h3. Activation des changements
168 1 Patrice Nadeau
169
Relire la configuration d'Apache
170
<pre><code class="bash">
171 27 Patrice Nadeau
systemctl reload apache2.service
172 1 Patrice Nadeau
</code></pre>
173
174
Commandes
175 10 Patrice Nadeau
* _apache2ctl -S_ : liste les serveurs virtuels