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 | ||
linux:installation:openssl [2022/09/03 14:47] – [Creating an Apache Configuration Snippet with Strong Encryption Settings] tutospisto | linux:installation:openssl [2022/09/03 14:58] (Version actuelle) – [Step 5 — Testing Encryption] tutospisto | ||
---|---|---|---|
Ligne 52: | Ligne 52: | ||
Paste the following configuration into the ssl-params.conf file we opened: | Paste the following configuration into the ssl-params.conf file we opened: | ||
- | < | + | < |
SSLCipherSuite EECDH+AESGCM: | SSLCipherSuite EECDH+AESGCM: | ||
SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 | SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 | ||
Ligne 69: | Ligne 69: | ||
</ | </ | ||
+ | Save and close the file when you are finished. | ||
+ | |||
+ | Modifying the Default Apache SSL Virtual Host File | ||
+ | |||
+ | Next, let’s modify / | ||
+ | |||
+ | Before we go any further, let’s back up the original SSL Virtual Host file : | ||
+ | <code bash> | ||
+ | Now, open the SSL Virtual Host file to make adjustments : | ||
+ | <code bash> | ||
+ | |||
+ | |||
+ | Inside, with most of the comments removed, the Virtual Host block should look something like this by default: | ||
+ | |||
+ | **/ | ||
+ | <code apache[enable_line_numbers=1]> | ||
+ | < | ||
+ | < | ||
+ | SServerAdmin webmaster@localhost | ||
+ | |||
+ | DocumentRoot / | ||
+ | |||
+ | ErrorLog ${APACHE_LOG_DIR}/ | ||
+ | CustomLog ${APACHE_LOG_DIR}/ | ||
+ | |||
+ | SSLEngine on | ||
+ | |||
+ | SSLCertificateFile | ||
+ | SSLCertificateKeyFile / | ||
+ | |||
+ | < | ||
+ | SSLOptions +StdEnvVars | ||
+ | </ | ||
+ | < | ||
+ | SSLOptions +StdEnvVars | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | We will be making some minor adjustments to the file. We will set the normal things we’d want to adjust in a Virtual Host file (ServerAdmin email address, ServerName, etc.), and adjust the SSL directives to point to our certificate and key files. Again, if you’re using a different document root, be sure to update the DocumentRoot directive. | ||
+ | |||
+ | After making these changes, your server block should look similar to this: | ||
+ | |||
+ | / | ||
+ | |||
+ | <code apache[enable_line_numbers=1]> | ||
+ | < | ||
+ | < | ||
+ | ServerAdmin your_email@example.com | ||
+ | ServerName server_domain_or_IP | ||
+ | |||
+ | DocumentRoot / | ||
+ | |||
+ | ErrorLog ${APACHE_LOG_DIR}/ | ||
+ | CustomLog ${APACHE_LOG_DIR}/ | ||
+ | |||
+ | SSLEngine on | ||
+ | |||
+ | SSLCertificateFile | ||
+ | SSLCertificateKeyFile / | ||
+ | |||
+ | < | ||
+ | SSLOptions +StdEnvVars | ||
+ | </ | ||
+ | < | ||
+ | SSLOptions +StdEnvVars | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Save and close the file when you are finished. | ||
+ | |||
+ | === (Recommended) Modifying the HTTP Host File to Redirect to HTTPS === | ||
+ | As it stands now, the server will provide both unencrypted HTTP and encrypted HTTPS traffic. For better security, it is recommended in most cases to redirect HTTP to HTTPS automatically. If you do not want or need this functionality, | ||
+ | |||
+ | To adjust the unencrypted Virtual Host file to redirect all traffic to be SSL encrypted, open the / | ||
+ | <code bash> | ||
+ | |||
+ | Inside, within the VirtualHost configuration blocks, add a Redirect directive, pointing all traffic to the SSL version of the site: | ||
+ | |||
+ | **/ | ||
+ | |||
+ | <code bash>< | ||
+ | . . . | ||
+ | |||
+ | Redirect "/" | ||
+ | |||
+ | . . . | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | Save and close the file when you are finished. | ||
+ | |||
+ | That’s all of the configuration changes you need to make to Apache. Next, we will discuss how to update firewall rules with ufw to allow encrypted HTTPS traffic to your server. | ||
+ | ===== Step 3 — Adjusting the Firewall ===== | ||
+ | |||
+ | Je n’ai pas réalisé cette étape. | ||
+ | |||
+ | ===== Step 4 — Enabling the Changes in Apache ===== | ||
+ | |||
+ | Now that we’ve made our changes and adjusted our firewall, we can enable the SSL and headers modules in Apache, enable our SSL-ready Virtual Host, and then restart Apache to put these changes into effect. | ||
+ | |||
+ | Enable mod_ssl, the Apache SSL module, and mod_headers, | ||
+ | |||
+ | <code bash> | ||
+ | sudo a2enmod ssl | ||
+ | sudo a2enmod headers | ||
+ | sudo a2ensite default-ssl | ||
+ | sudo a2enconf ssl-params | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | At this point, the site and the necessary modules are enabled. We should check to make sure that there are no syntax errors in our files. Do this by typing: | ||
+ | <code bash> | ||
+ | |||
+ | |||
+ | |||
+ | If everything is successful, you will get a result that looks like this: | ||
+ | |||
+ | <code bash> | ||
+ | Syntax OK</ | ||
+ | |||
+ | |||
+ | As long as your output has Syntax OK in it, then your configuration file has no syntax errors and you can safely restart Apache to implement the changes: | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | |||
+ | With that, your self-signed SSL certificate is all set. You can now test that your server is correctly encrypting its traffic. | ||
+ | |||
+ | |||
+ | ===== Step 5 — Testing Encryption ===== | ||
+ | |||
+ | |||
+ | You’re now ready to test your SSL server. | ||
+ | |||
+ | Open your web browser and type <code bash> | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Because the certificate you created isn’t signed by one of your browser’s trusted certificate authorities, | ||
+ | |||
+ | You should be taken to your site. If you look in the browser address bar, you will see a lock with an « x » over it or another similar “not secure” notice. In this case, this just means that the certificate cannot be validated. It is still encrypting your connection. | ||
+ | |||
+ | If you configured Apache to redirect HTTP to HTTPS, you can also check whether the redirect functions correctly: | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | If this results in the same icon, this means that your redirect worked correctly. However, the redirect you created earlier is only a temporary redirect. If you’d like to make the redirection to HTTPS permanent, continue on to the final step. | ||
+ | ===== Step 6 — Changing to a Permanent Redirect ===== | ||
+ | |||
+ | |||
+ | If your redirect worked correctly and you are sure you want to allow only encrypted traffic, you should modify the unencrypted Apache Virtual Host again to make the redirect permanent. | ||
+ | |||
+ | Open your server block configuration file again: | ||
+ | <code bash> | ||
+ | |||
+ | Find the Redirect line we added earlier. Add permanent to that line, which changes the redirect from a 302 temporary redirect to a 301 permanent redirect: | ||
+ | |||
+ | **/ | ||
+ | <code bash>< | ||
+ | . . . | ||
+ | |||
+ | Redirect permanent "/" | ||
+ | |||
+ | . . . | ||
+ | </ | ||
+ | |||
+ | Save and close the file. | ||
+ | |||
+ | Check your configuration for syntax errors: | ||
+ | <code bash> | ||
+ | |||
+ | If this command doesn’t report any syntax errors, restart Apache: | ||
+ | <code bash> | ||
+ | This will make the redirect permanent, and your site will only serve traffic over HTTPS. | ||