Konfigurasi SSL Let’s Encrypt dengan Apache di Linux Mint 20 Integrasi Cloudflare + MikroTik + Server Lokal

Konfigurasi SSL Let’s Encrypt dengan Apache di Linux Mint 20 Integrasi Cloudflare + MikroTik + Server Lokal

1. Overview & Arsitektur

Dokumentasi ini menjelaskan langkah-langkah lengkap konfigurasi SSL Let’s Encrypt menggunakan Apache sebagai web server di Linux Mint 20, dengan routing melalui Cloudflare dan MikroTik sebagai gateway.

Alur Koneksi:

Internet → Cloudflare (Proxy) → IP Publik → MikroTik (NAT) → Server Linux Mint

Port 80 (HTTP) : untuk certbot challenge & redirect

Port 443 (HTTPS) : traffic terenkripsi SSL

Spesifikasi Lingkungan:

Komponen Detail
OS Server Linux Mint 20 (Ubuntu 20.04 base)
Web Server Apache 2.4
SSL Provider Let’s Encrypt (Certbot)
DNS / CDN Cloudflare
Gateway MikroTik Router
Domain example-hospital.com

 

2. Konfigurasi MikroTik (Port Forward)

MikroTik perlu dikonfigurasi untuk meneruskan traffic dari IP publik ke server lokal menggunakan NAT Destination (dstnat).

2.1 Via Terminal / SSH MikroTik

/ip firewall nat

add chain=dstnat protocol=tcp dst-port=80 \

action=dst-nat to-addresses=192.168.x.x \

to-ports=80 comment=”HTTP ke Server”

add chain=dstnat protocol=tcp dst-port=443 \

action=dst-nat to-addresses=192.168.x.x \

to-ports=443 comment=”HTTPS ke Server”

2.2 Via Winbox (GUI)

Buka menu: IP → Firewall → NAT → klik tombol [+]

Field Rule HTTP (Port 80) Rule HTTPS (Port 443)
Chain dstnat dstnat
Protocol tcp tcp
Dst. Port 80 443
Action dst-nat dst-nat
To Address 192.168.x.x 192.168.x.x
To Ports 80 443

ℹ️ Ganti 192.168.x.x dengan IP lokal server Linux Mint. Untuk mengetahui IP server: jalankan perintah ‘ip a’ di terminal server.

ℹ️ Untuk mencegah IP server berubah, set IP statis atau binding MAC di MikroTik: IP → DHCP Server → Leases → Make Static.

 

3. Konfigurasi Cloudflare DNS

Tambahkan dua DNS record di Cloudflare Dashboard → DNS → Records:

Type Name Content Proxy Status
A @ IP_PUBLIK_KAMU Proxied
A www IP_PUBLIK_KAMU Proxied

SSL/TLS Mode Cloudflare:

Setelah sertifikat SSL berhasil dipasang di server, ubah mode SSL di Cloudflare:

Dashboard Cloudflare → SSL/TLS → Overview → pilih Full (Strict)

ℹ️ Jangan gunakan mode ‘Flexible’ karena akan menyebabkan redirect loop (ERR_TOO_MANY_REDIRECTS).

 

4. Instalasi & Konfigurasi Apache

4.1 Install Apache dan Certbot

sudo apt update

sudo apt install apache2 certbot python3-certbot-apache -y

sudo a2enmod ssl rewrite headers proxy proxy_http

sudo systemctl restart apache2

4.2 Buat Virtual Host

sudo nano /etc/apache2/sites-available/example-hospital.com.conf

Isi konfigurasi awal (HTTP):

<VirtualHost *:80>

ServerName example-hospital.com

ServerAlias www.example-hospital.com

DocumentRoot /var/www/example-hospital

<Directory /var/www/example-hospital>

AllowOverride All

Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/rsud_error.log

CustomLog ${APACHE_LOG_DIR}/rsud_access.log combined

</VirtualHost>

sudo a2ensite example-hospital.com.conf

sudo apache2ctl configtest

sudo systemctl reload apache2

 

5. Generate Sertifikat SSL Let’s Encrypt

5.1 Jalankan Certbot

Sebelum menjalankan certbot, pastikan DNS record sudah terpropagasi. Verifikasi dengan:

nslookup example-hospital.com

nslookup www.example-hospital.com

Jika sudah resolve, jalankan certbot:

sudo certbot –apache -d example-hospital.com -d www.example-hospital.com

Certbot akan otomatis memodifikasi konfigurasi Apache dan menambahkan blok SSL. Saat ditanya pilihan redirect, pilih opsi Redirect (HTTP → HTTPS).

5.2 Hasil Konfigurasi Apache Setelah Certbot

<VirtualHost *:80>

ServerName example-hospital.com

ServerAlias www.example-hospital.com

Redirect permanent / https://example-hospital.com/

</VirtualHost>

 

<VirtualHost *:443>

ServerName example-hospital.com

ServerAlias www.example-hospital.com

DocumentRoot /var/www/example-hospital

<Directory /var/www/example-hospital>

AllowOverride All

Require all granted

</Directory>

SSLEngine on

SSLCertificateFile /etc/letsencrypt/live/example-hospital.com/fullchain.pem

SSLCertificateKeyFile /etc/letsencrypt/live/example-hospital.com/privkey.pem

Include /etc/letsencrypt/options-ssl-apache.conf

RequestHeader set X-Forwarded-Proto “https”

</VirtualHost>

 

6. Auto Renewal Sertifikat

Certbot secara otomatis membuat systemd timer untuk pembaruan sertifikat. Sertifikat Let’s Encrypt berlaku 90 hari dan akan diperbarui otomatis.

6.1 Cek Status Timer

sudo systemctl status certbot.timer

6.2 Test Renewal

sudo certbot renew –dry-run

ℹ️ Jika dry-run berhasil tanpa error, auto renewal sudah berjalan dengan benar.

 

7. Troubleshooting

7.1 ERR_TOO_MANY_REDIRECTS

Penyebab: Mode SSL Cloudflare diset ke ‘Flexible’ sehingga terjadi redirect loop.

Solusi: Ubah SSL/TLS mode di Cloudflare dari Flexible ke Full atau Full (Strict).

7.2 NXDOMAIN saat Certbot

Penyebab: DNS record untuk domain belum ada atau belum propagasi.

Solusi: Pastikan record A untuk @ dan www sudah ditambahkan di Cloudflare, tunggu 1-2 menit lalu coba lagi.

7.3 HTTP ERROR 500

Penyebab umum: konfigurasi database salah, modul PHP kurang, atau permission file salah.

Langkah diagnosa:

# Cek error log Apache

sudo tail -50 /var/log/apache2/error.log

 

# Aktifkan display error sementara di PHP

ini_set(‘display_errors’, 1);

error_reporting(E_ALL);

 

# Cek modul PHP

php -m | grep -E ‘mysqli|pdo|json’

 

# Install jika belum ada

sudo apt install php-mysql php-json -y

sudo systemctl restart apache2

7.4 .htaccess Tidak Terbaca

Pastikan nama file adalah .htaccess (bukan _htaccess), dan AllowOverride All sudah diset di konfigurasi Apache. Aktifkan juga mod_rewrite:

sudo a2enmod rewrite

sudo systemctl restart apache2

7.5 Koneksi Database Gagal (PHP + MySQL)

Di Linux, user root MySQL biasanya menggunakan auth_socket bukan password biasa. Buat user khusus untuk aplikasi:

sudo mysql -u root

CREATE USER ‘rsud_user’@’localhost’ IDENTIFIED BY ‘password_aman’;

GRANT ALL PRIVILEGES ON db_rsud.* TO ‘rsud_user’@’localhost’;

FLUSH PRIVILEGES;

EXIT;

 

8. Akses HTTP Lokal Tetap Berjalan

Apache tetap mendengarkan di port 80 secara lokal. Akses dari jaringan internal menggunakan IP lokal server tetap dapat dilakukan tanpa SSL:

http://192.168.x.x → Halaman default Apache

http://192.168.x.x/api-… → Aplikasi lokal

Untuk vhost terpisah khusus akses lokal, tambahkan konfigurasi berikut:

sudo nano /etc/apache2/sites-available/local.conf

<VirtualHost *:80>

ServerName 192.168.x.x

DocumentRoot /var/www/html

<Directory /var/www/html>

AllowOverride All

Require all granted

</Directory>

</VirtualHost>

sudo a2ensite local.conf && sudo systemctl reload apache2

 

Related Post

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x