DEV Community

Fega Suseno
Fega Suseno

Posted on • Updated on

Install let's Encrypt In On-Premise Server

Postingan ini akan membahas secure http dengan free ssl let's encrypt. Kali ini kita akan bermain dengan study kasus sederhana terkait ssl le's encrypt.

Study Case:
Aplikasi web-based berjalan pada On Premise server dengan keperluan akses from anywhere. Akses via http, server on premise di forward menggunakan public IP, yang mana IP publicnya kita arahkan ke domain. Kita ambil contoh nama domainya seno.com. Jadi ketika kita ping domain tersebut akan muncul IP public saya. Akan tetapi untuk dst.port saya setting 2480 untuk port 80 dan 2443 untuk port 443. Sehingga ketika kita ingin akses http jadi seperti ini seno.com:2480 dan ketika ingin https kita akses seno.com:2443. Berikut topologinya

Image description

Lab Konfigurasi Let's Encrypt
Kita akan lakukan konfigurasi pada server dengan OS Ubuntu 20.04 LTS. Pertama yang harus kita lakukan adalah menginstall certbot

apt install certbot python3-certbot-apache
Enter fullscreen mode Exit fullscreen mode

Kemudian pastikan port 80 dan 443 terbuka, namun sesuai study case diatas artinya kita perlu menambahkan port forwarding port 80 dan 443. Dalam kasus ini saya tambahkan port forwarding pada router mikrotik untuk port 80 dan 443. Untuk caranya saya tidak akan jelaskan disini, kepanjangan. Intinya kini ada 4 dst.port pada rule forwarding, yaitu port 2480,2443, 80, dan 443. Ini dilakukan karena let's encrypt membutuhkan open port 80 dan 443. Kita asumsikan sudah melakukan port forwarding 80 dan 443 pada router (dalam kasus ini menggunakan mikrotik).

Selanjutnya jalankan certbot untuk generate sertifikat let's encrypt

certbot --apache -d seno.com
Enter fullscreen mode Exit fullscreen mode

Maka akan muncul pertanyaan berikut:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) 
(Enter 'c' to cancel): your.email@mail.com
Enter fullscreen mode Exit fullscreen mode

Masukan email untuk notifikasi dari Let's Encrypt, setelah itu tekan enter

Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.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
Enter fullscreen mode Exit fullscreen mode

Ketikan A untuk menyetejui semua term & service lalu tekan enter

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
Enter fullscreen mode Exit fullscreen mode

Pada bagian ini optional, intinya kita akan berlangganan news EFF atau tidak. EFF adalah organisasi yang mengembangkan certbot. Disini saya pilih N lalu tekan enter.

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
Enter fullscreen mode Exit fullscreen mode

Pada bagian ini kita diminta untuk meredirect http ke https secara manual via browser atau redirect https secara otomatis. Rekomendasinya pilih no 2 agar ketika akses seno.com pada browser otomatis diarahkan ke https://seno.com
Perlu diperhatikan jika ada kesalahan atau failed request sebanyak 3x maka akan perlu waktu 3 jam untuk kembali request. cek baik-baik konfigurasinya.

Jika sudah selesai untuk mengecek sslnya bisa via link berikut
https://www.ssllabs.com/ssltest/analyze.html?d=namadomain.com

atau bisa juga lewat www.sslshopper.com

Untuk memperbarui request let's encrypt kita hanya perlu menjalankan

cerbot renew 
Enter fullscreen mode Exit fullscreen mode

Biasanya akan di buatkan cronjob untuk mendeteksi ketika sertifikat expired. Certbot otomatis menambahkan cronjob pada directory /etc/cron.d/certbot. Intinya certbot akan melakuan request sertifikat otomatis untuk mencegah expire sertifikat.

Catatan
Untuk versi Centos 7 ke atas untuk renew certbot tidak dibuatkan cron otomatis oleh certbot. Untuk mengatasi hal ini maka perlu dibuatkan cronjob secara manual, berikut petunjuknya

crontab -e
Enter fullscreen mode Exit fullscreen mode

Setlah itu masukan script cron berikut

0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew
Enter fullscreen mode Exit fullscreen mode

Tekan tombol esc lalu ketikan :wq untuk write and quit
Setelah selesai seharusnya certbot akan otomatis renew sertifikatnya.

Top comments (1)

Collapse
 
zer0network profile image
zer0network

jncx