GNU/Linux >> Belajar Linux >  >> Panels >> Panels

Cara Mengamankan Nginx dengan Let's Encrypt di Ubuntu 20.04

Mengamankan situs web yang berjalan dengan Nginx sebagai server web dapat dilakukan dengan Let's Encrypt, dan itulah sebabnya kami menulis tutorial ini untuk Anda.

Let's Encrypt adalah Otoritas Sertifikat yang menyediakan sertifikat TLS/SSL gratis yang berlaku selama 90 hari. SSL adalah singkatan dari Secure Sockets Layer dan sertifikat SSL adalah sertifikat digital yang memungkinkan koneksi terenkripsi dan otentikasi identitas situs web. Dalam posting blog ini, kami akan menggunakan Certbot untuk mendapatkan sertifikat SSL gratis untuk Nginx.

Menginstal sertifikat SSL Let's Encrypt Gratis di Ubuntu 20.04 dengan Certbot adalah proses yang mudah dan membutuhkan waktu hingga 10 menit. Mari kita mulai!

Prasyarat

  • Pemasangan baru Ubuntu 20.04
  • Hak istimewa pengguna:pengguna root atau non-root dengan hak istimewa sudo
  • Valid Catatan domain yang diarahkan ke alamat IP server Anda (domainanda.com dan www.domainanda.com)

Perbarui Sistem

Sebelum memulai proses instalasi, kita perlu memperbarui sistem untuk mendapatkan paket dan pembaruan terbaru yang tersedia.

sudo apt update -y && sudo apt upgrade -y

Instal Server Web Nginx

Untuk menginstal server web Nginx, jalankan perintah berikut:

sudo apt install nginx -y

Setelah instalasi selesai, aktifkan dan mulai layanan Nginx:

sudo systemctl enable nginx && sudo systemctl start nginx

Untuk memeriksa apakah semuanya baik-baik saja, periksa status layanan:

sudo systemctl status nginx

Anda akan menerima output berikut:

root@vps:~# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-02-06 19:34:56 UTC; 11s ago
       Docs: man:nginx(8)
    Process: 322857 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 322858 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 322859 (nginx)
      Tasks: 5 (limit: 4617)
     Memory: 5.0M
     CGroup: /system.slice/nginx.service
             ├─322859 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;

Buat Host Virtual Nginx

Sebelum kita melanjutkan dengan menginstal Free Let's Encrypt kita perlu membuat file virtual host yang berisi nama domain kita. Masuk ke direktori konfigurasi Nginx dan buat filenya.

cd /etc/nginx/conf.d/ && sudo nano yourdomain.com.conf

Tempel, baris kode berikut.

server {
        listen 80;
        root /var/www/html;
        index  index.php index.html index.htm;
        server_name yourdomain.com;

        error_log /var/log/nginx/yourdomain.com_error.log;
        access_log /var/log/nginx/yourdomain.com_access.log;

        client_max_body_size 100M;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
}

Periksa sintaks konfigurasi Nginx jika OK.

nginx -t

Anda akan menerima output berikut:

root@vps:/etc/nginx/conf.d# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Jika Anda menerima output ini, Anda dapat memulai ulang layanan Nginx dan mengakses situs web Anda.

sudo systemctl restart nginx

Instal Certbot

Saat ini, situs web kami menjalankan protokol HTTP. Memasang sertifikat SSL Let's Encrypt Gratis akan membuat situs web kami berjalan dengan aman melalui protokol HTTPS. Sebelum kita mulai dengan mendapatkan sertifikat, kita perlu menginstal python certbot untuk Nginx.

sudo apt install certbot python3-certbot-nginx

Setelah certbot berhasil diinstal, kita dapat melanjutkan dengan langkah utama dalam tutorial ini tentang mendapatkan sertifikat SSL.

Mendapatkan Sertifikat SSL

Untuk menjalankan certbot dengan plugin Nginx yang menentukan nama domain Anda, jalankan perintah berikut:

sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Setelah Anda menjalankan perintah ini, akan ada beberapa entri yang perlu Anda isi, seperti alamat email, persetujuan tentang syarat dan ketentuan, apakah Anda ingin membagikan alamat email Anda atau tidak, dan opsi pengalihan.

root@vps:~# sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
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]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: N
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for yourdomain.com
http-01 challenge for www.yourdomain.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/example.conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/example.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
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/example.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/example.conf

Jika semuanya sudah diatur sebagaimana mestinya, sertifikat akan dipasang dan Anda akan menerima pesan di bawah ini.

Congratulations! You have successfully enabled https://yourdomain.com and
https://www.yourdomain.com

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/yourdomain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/yourdomain.com/privkey.pem
   Your cert will expire on 2022-05-07. 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

Sekarang, Anda dapat mengakses situs web Anda dengan aman di https://domainanda.com

Selamat! Anda berhasil mengamankan Nginx dengan sertifikat SSL Let's Encrypt Gratis di server Ubuntu 20.04 Anda.

Tentu saja, Anda tidak perlu menginstal sertifikat SSL sendiri, dan jika Anda menggunakan salah satu layanan Hosting VPS SSD kami, dalam hal ini Anda dapat meminta administrator sistem pakar kami untuk menginstalnya untuk Anda dan mengamankan situs web Anda. Mereka tersedia 24×7 dan akan segera memenuhi permintaan Anda.

Jika Anda menyukai posting ini, tentang cara mengamankan Nginx dengan Lets Encrypt di Ubuntu 20.04, silakan bagikan dengan teman-teman Anda di jejaring sosial menggunakan tombol di bawah ini atau cukup tinggalkan komentar di bagian komentar. Terima kasih.


Panels
  1. Amankan Nginx dengan Let's Encrypt di Ubuntu 18.04 - Bagaimana cara melakukannya?

  2. Cara Menginstal Elgg dengan Nginx di Ubuntu 18.04

  3. Cara Instal Gitea dengan NGINX dan Let's Encrypt SSL Gratis di Ubuntu 20.04

  1. Cara Mengamankan Nginx dengan Letsencrypt di Ubuntu 20.04

  2. Cara menginstal Elgg dengan Nginx di Ubuntu 14.04

  3. Cara Menginstal Joomla dengan Nginx di Ubuntu 18.04

  1. Cara Mengamankan Nginx dengan Lets Encrypt Di Ubuntu 20.04 / 18.04

  2. Amankan Nginx dengan Lets Encrypt di Ubuntu 18.04

  3. Cara Menginstal Let's Encrypt di Ubuntu 20.04 dengan Apache