How to Install Free SSL on Nginx Alma Linux 10

How to Install Free SSL on Nginx Alma Linux 10

If you manage a website using Nginx on Alma Linux, you need to install SSL so that your website can be accessed securely. This tutorial covers how to install free SSL on Nginx Alma Linux 10, where the website installation folder is a continuation of How to Install WordPress on Alma Linux 10 with LEMP Stack previously.

Prerequisites for Installing Free SSL on Nginx Alma Linux 10

Before installing SSL, please ensure you have met the following prerequisites:

  • The domain DNS A record is already pointing to the server IP
  • Ports 80 and 443 are open in the firewall
  • Nginx is running
  • The website is accessible via http
  • Your domain server_name is already in the Nginx virtual host

If all prerequisites are met, you can proceed to the steps for installing free SSL.

How to Install Free SSL on Nginx Alma Linux 10

Before starting, ensure your firewall allows traffic to ports 80 and 443, or you can reopen them.

sudo firewall-cmd --permanent --add-service=httpsudo firewall-cmd --permanent --add-service=httpssudo firewall-cmd --reload

Next, let's move straight to the first step.

1. Install EPEL + Certbot

For free SSL, we will request it using Certbot, so first install Certbot and the Nginx plugin for Certbot.

sudo dnf install epel-release -ysudo dnf install certbot python3-certbot-nginx -y
Cara Install SSL Gratis di Nginx Alma Linux 10 - WPGan.com - 1

2. Request SSL Certificate

Once Certbot is installed, you can immediately request an SSL certificate for your website.

sudo certbot --nginx \  -d tutorial.wpgan.com \  -d www.tutorial.wpgan.com \  --email [email protected] \  --agree-tos \  --no-eff-email

Certbot will automatically modify the existing Nginx configuration and set up an HTTP to HTTPS redirect.

Cara Install SSL Gratis di Nginx Alma Linux 10 - WPGan.com - 2

3. Test Website Access

If the installation process is complete, try accessing your website and ensure it can be accessed via https.

Cara Install SSL Gratis di Nginx Alma Linux 10 - WPGan.com - 3

If the website is accessible via https, also make sure to verify SSL auto-renewal so that when it expires, the SSL is automatically renewed, as SSL is only active for about 3 months.

4. Verify SSL Auto-renewal

Certbot automatically creates a systemd timer that runs twice a day. You can verify whether the timer is active or not.

sudo systemctl status certbot-renew.timer

Also, try a dry run test to ensure auto-renewal will work correctly later.

sudo certbot renew --dry-run

If the output is Congratulations, all simulated renewals succeeded, there should be no issues later when renewing the SSL.

Cara Install SSL Gratis di Nginx Alma Linux 10 - WPGan.com - 4

That is the easy way to install free SSL on Nginx Alma Linux 10 that you can apply. If there is an error Could not install certificate / OpenSSL key length, that error is usually a bug in certain versions of AlmaLinux 9. The solution is to generate the SSL manually without the flag --nginx, then manually configure the virtual host, for example like this

server {    listen 80;    server_name tutorial.wpgan.com www.tutorial.wpgan.com;    return 301 https://tutorial.wpgan.com$request_uri;}
server {    listen 443 ssl;    server_name tutorial.wpgan.com www.tutorial.wpgan.com;    root /var/www/html/tutorial.wpgan.com;    index index.php index.html index.htm;
    ssl_certificate /etc/letsencrypt/live/tutorial.wpgan.com/fullchain.pem;    ssl_certificate_key /etc/letsencrypt/live/tutorial.wpgan.com/privkey.pem;
    if ($host = www.tutorial.wpgan.com) {        return 301 https://tutorial.wpgan.com$request_uri;    }
    location / {        try_files $uri $uri/ /index.php?$args;    }
    location ~ \.php$ {        fastcgi_pass unix:/var/opt/remi/php85/run/php-fpm/www.sock;        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;        include fastcgi_params;    }
    location ~ /\.ht {        deny all;    }
    client_max_body_size 64M;}

Make sure to change the domain name and the path for ssl_certificate and ssl_certificate_key to match the path of the SSL file you obtained.

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...