Dump the code
Best ressources to improve your Python Skills

Securing your sites with SSL/TLS

Created 11 months ago
Posted By admin
3min read
To generate and install SSL certificates for Nginx, you can use tools like Let's Encrypt.

Step 1: Install Certbot

Install Certbot, the official client for Let's Encrypt:

sudo apt-get update
sudo apt-get install certbot
sudo apt-get install certbot python3-certbot-nginx

Step 2: Obtain and Install the Certificate

Run Certbot to obtain and install the certificate:

sudo certbot --nginx -d example.com
Follow the prompts to configure Certbot. Certbot will automatically configure Nginx to use the obtained certificate.

Step 3: Configure Nginx

Check that Certbot has added the SSL configuration to your Nginx site configuration file. It usually looks similar to this:

server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    # Additional SSL settings
}
  • ssl_certificate: this directive is used to specify the path to the SSL certificate file. The SSL certificate contains the public key of the server and is presented to clients during the SSL/TLS handshake process to establish a secure connection.
  • ssl_certificate_key: this directive is used to specify the path to the private key file corresponding to the SSL certificate. The private key is kept secret and is used to decrypt information encrypted with the public key in the certificate.
  • ssl_dhparam: this directive is used to configure the file path to the Diffie-Hellman parameters file. The Diffie-Hellman parameters are used in the key exchange process during the SSL/TLS handshake to establish a shared secret key between the server and the client. This shared key is then used to derive session keys for encrypting the communication.

Step 4: Automatic Renewal

Let's Encrypt certificates are valid for 90 days. To set up automatic renewal, run:

sudo certbot renew --dry-run
This ensures that the renewal process works correctly.

Notes:

- Always backup your private key and certificate files.
- Adjust SSL settings based on your security requirements.
- Regularly update your certificates and consider automating the renewal process.

After following these steps, your Nginx server should be configured with SSL certificates, ensuring secure communication between clients and the server.
Topics

Mastering Nginx

27 articles

Bash script

2 articles

Crontab

2 articles