In this guide, we will walk you through the process of creating an SSL certificate with certbot on your new web server. If you haven’t already, please perform your initial server setup to ensure you can proceed on with this guide. With certbot installed, you can generate SSL certificates and configure your web server force https redirection.
If you’re ready to secure your entire domain and automatically configure your web server for HTTPS, use the following command:
Apache
sudo certbot --apache
Nginx
sudo certbot --nginx
This command will generate the SSL certificates and automatically modify your web server configuration to enable HTTPS and optionally redirect HTTP requests to HTTPS.
If you need to create SSL certificates for specific domains (for example, if you’re hosting multiple sites or using a system hostname), use this command:
sudo certbot –apache -d example.com -d www.example.com
Replace example.com and www.example.com with your actual domain names.
If you prefer to only create SSL certificates without modifying your web server’s configuration (ideal for staging or testing environments), run:
Apache
sudo certbot certonly --apache
Nginx
sudo certbot certonly --nginx
This option will create the SSL certificates without affecting your existing server settings.
During the set up process certbot will prompt you regarding automatic redirect to HTTPs, for most cases this should be enabled unless you have another means in place.
This will prevent visitors from being able to accidently visit the unsecured version of those pages.
After going through that process restart your web server. Now you can test your SSL installation by visiting your site using https:// to confirm the SSL is present and trying to visit http to test the redirect. You can also use an external SSL testing tool similar to the one provided by Qualys.