Install Letsencrypt Debian 9 Nginx


Install Letsencrypt Debian 9 Nginx

What is Letsencrypt?

Letsencrypt is an open source, free, automated SSL service that provides users with the ability to secure their websites and use HTTPS instead of plain HTTP. It is the preferred security solution for most webmasters and hosting providers who want to easily and quickly secure their web resources and ensure their websites are reachable over secure connections. The service is provided by the non-profit Internet Security Research Group who is develop and maintain the software for free.

What is Nginx?

Nginx is a web server and a reverse proxy for HTTP, SMTP, and other network services. It is free, open source software and can be used to host web applications, provide proxy services and load balance requests. Nginx uses an efficient event-based, non-blocking I/O model that can handle hundreds and thousands of simultaneous requests, making it a capable and effective web server solution.

How Can I Install Letsencrypt on Debian 9 with Nginx?

Installing Letsencrypt on Debian 9 with Nginx is a simple process that only requires a few steps.

  1. Install the certbot client software.
  2. Create a virtual host configuration for your Nginx server.
  3. Request a new certificate with the Letsencrypt service.
  4. Install the certificate and adjust your server configuration.
  5. Update your Nginx server configuration.
  6. Verify your installation.

We will walk through each of these steps in detail.

Install the certbot client software.

The first step to installing Letsencrypt on Debian 9 is to install the certbot client software. Certbot is a command line utility for managing and obtaining SSL certificates from the Letsencrypt service. To install certbot, open a terminal window and enter the following command:


sudo apt-get install python-certbot-nginx

This will install the necessary components and packages required for using certbot with Nginx on Debian 9.

Create a virtual host configuration for your Nginx server.

Now that the certbot software has been installed, you need to create a virtual host configuration for your Nginx server. In your favorite text editor, open the following file:


/etc/nginx/sites-available/default

In the default file, add the following section:


server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.html index.htm;
...
}

This section creates a basic virtual host configuration that will make sure that requests to example.com and www.example.com will be served with the content located in the /var/www/example.com/html directory.

Request a new certificate with the Letsencrypt service.

Now that you have the certbot client software installed and a virtual host configuration set up, you can request a new certificate with the Letsencrypt service. To do this, open a terminal window and enter the following command:


sudo certbot --nginx

This will launch the certbot wizard and step you through the process of requesting your certificate. When prompted, enter the domain name that you want to secure with Letsencrypt and follow the instructions to complete the process.

Install the certificate and adjust your server configuration.

Once the certificate has been successfully requested and issued, you will need to install the certificate and adjust your Nginx server configuration. To install the certificate, enter the following command in the terminal:


sudo certbot --nginx -d example.com --install-cert

This command will install the certificate and the associated private key to the current directory. Now open the /etc/nginx/sites-available/default file again and add the following information to the virtual host section:


server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/example.com/cert.pem;
ssl_certificate_key /etc/letsencrypt/example.com/privkey.pem;
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.html index.htm;
...
}

This will tell Nginx to use the newly installed certificate and private key when responding to requests arriving on port 443 (HTTPS).

Update your Nginx server configuration.

The final step is to update your Nginx server configuration to redirect all requests arriving on port 80 (HTTP) to the HTTPS protocol. To do this, open the /etc/nginx/sites-available/default file and add the following information:


server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}

This configuration will redirect all incoming requests specified by the “server_name” parameter from HTTP to HTTPS.

Verify your installation.

Once you have completed the steps above, you should now be able to verify that your installation of Letsencrypt on Debian 9 is successful. To do this, open a web browser and navigate to your website. If the Letsencrypt SSL certificate is installed correctly, you should see the https protocol in the URL and the website should be reachable over a secure connection.

Conclusion

In this tutorial we have walked through the steps required to install Letsencrypt SSL certificates on a Debian 9 system. We have described how to install the certbot client software and how to create and configure virtual host configurations for Nginx. We have also discussed how to request and install certificates with the Letsencrypt service and how to adjust the server configuration to ensure proper operation.

Thank you for reading this article. If you want to find more information about setting up Letsencrypt on a Debian 9 system, please read our other articles.

Leave a Reply

Your email address will not be published. Required fields are marked *