Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
documentation:informatique:linux:apache:index [2019/01/22 13:14] – [③] f1sls | documentation:informatique:linux:apache:index [2019/05/05 16:22] (Version actuelle) – f1sls | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Apache ====== | ====== Apache ====== | ||
+ | |||
+ | ===== Sécurité ===== | ||
+ | * https:// | ||
===== SSL / https ===== | ===== SSL / https ===== | ||
Ligne 55: | Ligne 58: | ||
To override the default number of days for which the certificate is valid, you can specify -days X, where X is some other number. | To override the default number of days for which the certificate is valid, you can specify -days X, where X is some other number. | ||
- | Easier Alternative for STEP 2 | + | === Easier Alternative for STEP 2 === |
When the package ssl-cert is installed a self-signed certificate gets automatically created. The certificate is stored at | When the package ssl-cert is installed a self-signed certificate gets automatically created. The certificate is stored at | ||
Ligne 96: | Ligne 100: | ||
If you have multiple sites on your server that will use distinct certificates, | If you have multiple sites on your server that will use distinct certificates, | ||
====⑤==== | ====⑤==== | ||
+ | After creating your SSL site, its time to enable it. To enable your newly created site you need to run this command. | ||
+ | |||
+ | <code lang=" | ||
+ | $> a2ensite sitename | ||
+ | </ | ||
+ | |||
+ | Where " | ||
+ | |||
+ | ====⑥==== | ||
+ | |||
+ | It is very important to tell the server to listen on port 443. That's why you need to add a line to ports.conf (/ | ||
+ | |||
+ | <code lang=" | ||
+ | Listen 443 | ||
+ | Listen 80 | ||
+ | </ | ||
+ | |||
+ | ====⑦==== | ||
+ | Now restart the apache server to apply the changes. | ||
+ | |||
+ | <code lang=" | ||
+ | $> / | ||
+ | </ | ||
+ | |||
+ | or | ||
+ | |||
+ | <code lang=" | ||
+ | $> service apache2 restart | ||
+ | </ | ||
+ | |||
+ | ====⑧==== | ||
+ | Open your browser and type: | ||
+ | |||
+ | < | ||
+ | https:// | ||
+ | </ | ||
+ | |||
+ | where " | ||
+ | |||
+ | ===== Redirection http ➡ https ===== | ||
+ | [[https:// | ||
+ | ==== Redirect HTTP to HTTPS on Apache Using .htaccess File ==== | ||
+ | |||
+ | For this method, make sure mod_rewrite is enabled, otherwise enable it like this on Ubuntu/ | ||
+ | |||
+ | <code lang=" | ||
+ | $ sudo a2enmod rewrite [Ubuntu/ | ||
+ | </ | ||
+ | |||
+ | For CentOS/RHEL users, ensure that your have the following line in httpd.conf (mod_rewrite support – enabled by default). | ||
+ | |||
+ | LoadModule rewrite_module modules/ | ||
+ | Now you just need to edit or create .htaccess file in your domain root directory and add these lines to redirect http to https. | ||
+ | |||
+ | < | ||
+ | RewriteEngine On | ||
+ | RewriteCond %{HTTPS} | ||
+ | RewriteRule ^/?(.*) https:// | ||
+ | </ | ||
+ | |||
+ | Now, when a visitor types http:// | ||
+ | |||
+ | |||
+ | ==== Redirect HTTP to HTTPS on Apache Virtual Host ==== | ||
+ | Additionally, | ||
+ | |||
+ | The second is for the secure port 443. To redirect HTTP to HTTPS for all the pages of your website, first open the appropriate virtual host file. Then modify it by adding the configuration below. | ||
+ | |||
+ | < | ||
+ | NameVirtualHost *:80 | ||
+ | < | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | # etc... | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Save and close the file, then restart the HTTP sever like this. | ||
+ | |||
+ | <code lang=" | ||
+ | $ sudo systemctl restart apache2 | ||
+ | $ sudo systemctl restart httpd | ||
+ | </ | ||
+ | While the ''< |