GNU/Linux >> Belajar Linux >  >> Debian

Cara Mengatur Let's Encrypt SSL Certificate dengan Nginx di Debian 10 / Debian 9

Let's Encrypt adalah otoritas sertifikat yang menyediakan sertifikat SSL gratis untuk enkripsi TLS, diluncurkan pada April 2016.

Let's Encrypt tidak hanya menyediakan sertifikat SSL; itu juga mengotomatiskan pembuatan sertifikat, validasi, penandatanganan, implementasi, dan pembaruan sertifikat untuk situs web yang aman.

Saat ini, Let's Encrypt mendukung penginstalan otomatis sertifikat di Apache, Nginx, Plex, dan Haproxy.

Prasyarat

Saya menyarankan Anda untuk menyiapkan tumpukan LEMP di sistem Anda sebelum melanjutkan lebih jauh.

BACA: Cara Memasang LEMP Stack di Debian 10

BACA: Cara Memasang LEMP Stack di Debian 9

Siapkan Mari Enkripsi Sertifikat SSL dengan Nginx

Instal Certbot

Untuk menghasilkan sertifikat untuk domain Anda, Anda harus memiliki akses terminal dan klien ACME Certbot. Klien Certbot menangani penerbitan dan pemasangan sertifikat tanpa waktu henti.

Certbot tersedia di repositori dasar Debian. Jadi, Anda dapat menggunakan perintah di bawah ini untuk menginstalnya.

sudo apt update

sudo apt install -y certbot python-certbot-nginx

Buat Virtualhost

Sekarang kita akan membuat virtual host untuk domain www.itzgeek.net.

Host virtual ini menyajikan versi HTTP domain Anda.
sudo nano /etc/nginx/conf.d/www.itzgeek.net.conf

Gunakan informasi di bawah ini.

server {
   server_name www.itzgeek.net;
   root /opt/nginx/www.itzgeek.net;

   location / {
       index index.html index.htm index.php;
   }

   access_log /var/log/nginx/www.itzgeek.net.access.log;
   error_log /var/log/nginx/www.itzgeek.net.error.log;

   location ~ \.php$ {
      include /etc/nginx/fastcgi_params;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /opt/nginx/www.itzgeek.net$fastcgi_script_name;
   }
}

Buat root dokumen untuk menyimpan file HTML.

sudo mkdir -p /opt/nginx/www.itzgeek.net

Ubah izin direktori.

sudo chown -R nginx:nginx /opt/nginx/www.itzgeek.net

Tempatkan contoh file HTML di root dokumen domain Anda.

echo "This is a test site @ www.itzgeek.net" | sudo tee /opt/nginx/www.itzgeek.net/index.html

Mulai ulang layanan Nginx.

sudo systemctl restart nginx

Buat / Perbarui Data DNS

Akses alat manajemen DNS atau Pendaftar domain Anda dan buat data A/CNAME untuk domain tersebut. Contoh:www.itzgeek.net.

Tunggu beberapa saat hingga rekaman menyebar.

Periksa propagasi DNS dengan Nslookup sudo apt install -y dnsutils utility.

Instal Let's Encrypt Certificate

Gunakan perintah certbot untuk membuat sertifikat Let's Encrypt dan konfigurasikan Nginx untuk menggunakan sertifikat tersebut.

sudo certbot --nginx

Ikuti perintah interaktif dan instal sertifikat.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]  << Enter Email ID

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A  << Agree to Terms and Conditions

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y  << Subscriber to Newsletter

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: www.itzgeek.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1  << Choose Site to Install Let's Encrypt
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.itzgeek.net
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/www.itzgeek.net.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2  << Redirect HTTP to HTTPS
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/www.itzgeek.net.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://www.itzgeek.net

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=www.itzgeek.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/www.itzgeek.net/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/www.itzgeek.net/privkey.pem
   Your cert will expire on 2019-10-28. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le


Arahkan permintaan HTTP non-www ke www HTTPS dengan Nginx (opsional)

Kami sekarang akan mengonfigurasi server Nginx untuk mengarahkan lalu lintas yang datang untuk situs HTTP non-www ke situs WW HTTPS, yaitu http://itzgeek.net>> https://www.itzgeek.net .

Di sini, kita akan mengedit file konfigurasi yang sama yang kita buat untuk situs versi HTTP.

sudo nano /etc/nginx/conf.d/www.itzgeek.net.conf

Tambahkan informasi di bawah ini di akhir file.

# Redirect NON-WWW HTTP to WWW HTTPS

server {
    if ($host = itzgeek.net) {
        return 301 https://www.itzgeek.net$request_uri;
    }


   server_name itzgeek.net;
    listen 80;
    return 404;

}

Mulai ulang layanan Nginx.

sudo systemctl restart nginx

Verifikasi Let's Encrypt Certificate

Verifikasi sertifikat Let's Encrypt dengan mengunjungi situs web Anda.

http://situs-http-Anda

ATAU

https://your-https-web-site

Anda seharusnya mendapatkan versi HTTPS dari situs Anda sekarang.

Uji Sertifikat SSL

Uji sertifikat SSL Anda untuk masalah apa pun dan peringkat keamanannya dengan membuka URL di bawah ini.

https://www.ssllabs.com/ssltest/analyze.html?d=www.itzgeek.net

Perbarui Sertifikat Let's Encrypt

Sertifikat Let's Encrypt memiliki validitas 90 hari, dan sangat disarankan untuk memperbarui sertifikat Anda sebelum kedaluwarsa. Berkat entri penjadwal bawaan /etc/cron.d/certbot yang berjalan dua kali sehari untuk memperbarui sertifikat yang akan kedaluwarsa.

Namun, saya menyarankan Anda untuk menjalankan perintah di bawah ini untuk mensimulasikan pembaruan otomatis sertifikat Anda.

sudo certbot renew --dry-run

Keluaran:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/www.itzgeek.net.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator nginx, Installer nginx
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for www.itzgeek.net
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of nginx server; fullchain is
/etc/letsencrypt/live/www.itzgeek.net/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/www.itzgeek.net/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.

Jika output mengonfirmasi bahwa pembaruan berfungsi dengan baik, maka pembaruan otomatis akan terjadi seperti yang diharapkan.

Kesimpulan

Itu saja. Saya harap Anda mempelajari cara Menyiapkan Let's Encrypt SSL Certificate dengan Nginx di Debian 10. Bagikan tanggapan Anda di bagian komentar.


Debian
  1. Cara Menginstal Drupal 9 dengan Nginx dan Mengenkripsi SSL di Debian 10

  2. Amankan Nginx dengan Let's Encrypt SSL di Debian 10/11

  3. Cara Menginstal Let's Encrypt SSL di Ubuntu 18.04 dengan Nginx

  1. Cara Menginstal Wekan Kanban dengan Nginx dan Mengenkripsi SSL di Debian 10

  2. Cara Setup Let's Encrypt SSL Certificate Dengan Nginx di CentOS 8 / RHEL 8 &CentOS 7 / RHEL 7

  3. Cara Setup Let's Encrypt SSL Certificate dengan Apache di CentOS 8 / RHEL 8 &CentOS 7 / RHEL 7

  1. Cara Instal WordPress dengan Apache dan Mari Enkripsi SSL di Debian 11

  2. Cara Menginstal Let's Encrypt SSL di Apache di Debian 11

  3. Cara Instal Drupal dengan Nginx dan Mari Enkripsi SSL di Debian 11