Web Server HTTPS : Secure HTTP Protocol pada CentOS

Biasanya kita hanya melihat sebuah site dengan tulisan “https” dipojok kiri atas. HTTPS merupakan kepanjangan dari Hypertext Transfer Protocol Secure yang merupakan sebuah protokol kombinasi antara HTTP (Hypertext Transfer Protocol) dan Cryptographic Protocol. Pada protokol ini selain menggunakan komunikasi plain text, juga menyandikan data sesi dengan menggunakan protokol SSL (Secure Socket Layer) atau Protokol TLS (Transport Layer Security). Pada umumnya Port yang digunakan adalah port 443 dan url yang digunakan adalah https://

Pada kali ini OS yang digunakan adalah CentOS6, step-nya untuk membuat https sebagai berikut :

1. Siapkan package-nya terlebih dahulu.

yum -y install mod_ssl openssl

2. Kemudian kita buat certified-nya, certified ini ada juga yang berbayar yang menggunakan jasa provider cert seperti digicert.com , namun kali ini kita akan membuat yang free.. hehehe.

# Generate private key
openssl genrsa -out ca.key 1024
# Generate CSR
openssl req -new -key ca.key -out ca.csr
# Generate Self Signed Key
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt
# Move the files to the correct locations
mv ca.crt /etc/pki/tls/certs
mv ca.key /etc/pki/tls/private/ca.key
mv ca.csr /etc/pki/tls/private/ca.csr

Kemudian kita harus mengupdate konfigurasi Apache SSL

#vi +/SSLCertificateFile /etc/httpd/conf.d/ssl.conf

Mengubah path untuk mencocokkan di mana file kunci disimpan.

#SSLCertificateFile /etc/pki/tls/certs/ca.crt

Kemudian mengatur path untuk Sertifikat Key File

#SSLCertificateKeyFile /etc/pki/tls/private/ca.key

restart Apache

#service httpd restart

3. Config http.conf

kita buat virtual host di http.conf, jika menggunakan apache / httpd default dari CentOS maka path untuk httpd.conf terletak di /etc/httpd/conf/httpd.conf, jika menggunakan apache bentuk tarball maka berada di /path/install/apache2/conf/httpd.conf. kita buat dengan menggunakan port 443 (ssl) kita akan buat Directoryroot-nya di /var/www/test maka dari itu kita buat terlebih dahulu foldernya “#mkdir /var/www/test“.

NameVirtualHost *:443
<VirtualHost *:443>
 SSLEngine on
 SSLCertificateFile /etc/pki/tls/certs/ca.crt
 SSLCertificateKeyFile /etc/pki/tls/private/ca.key
 <Directory /var/www/test>
 AllowOverride All
 </Directory>
 DocumentRoot /var/www/test
 ServerName 10.10.5.58
</VirtualHost>

4. Konfigure firewall

Iptables di config agar port 443 bisa diakses :

#iptables -A INPUT -p tcp --dport 443 -j ACCEPT

atau dengan cara edit di /etc/sysconfig/iptables

# vim /etc/sysconfig/iptables

# Firewall configuration written by system-config-securitylevel
# # Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT – [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp –icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp –dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 5666 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 5555 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited
COMMIT

untuk melihat iptables

#iptables -L -v

Kemudian restart service apache / http :

#/etc/init.d/httpd restart

5. Test dengan HTTPS

Buka browser, kemudian ketikan “https://localhost/” maka pertama kali akan di minta sertified-nya seperti dibawah ini.

Mudah bukan, Selamat mecobanya.

About andi

always try to be the best..
This entry was posted in Linux. Bookmark the permalink.

Leave a comment