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