Redirect port 80 ke 443 di apache2.

Menurut saya, cara redirect dari port 80 ke port 443 sebaiknya menggunakan module mod_rewrite bawaan paket software apache2. Cara ini lebih menghemat resource dan lebih cepat. Jurus ini berlaku di apache2-2.4.51 opensuse 15.3. Ada 2 file yang terlibat disini. File pertama adalah /etc/sysconfig/apache2. Di file ini, ketik “rewrite” di bagian APACHE_MODULES. File kedua ada di /etc/apache2/vhosts.d/. Buat file virtual host menggunakan standard apache2 yaitu vhost.subdomain.conf. Isi file tersebut dengan direktif sebagai berikut:
=====================================================================================

<IfDefine SSL>
<IfDefine !NOSSL>

##
## port 80
##
<VirtualHost *:80>  
ServerName siakad.pancabudi.ac.id
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
##
## port 443AllowOverride All
##
<VirtualHost *:443>

       #  General setup for the virtual host
       DocumentRoot “/home/taufik/mount-siakad”
       ServerName siakad.pancabudi.ac.id:443
       ServerAdmin [email protected]
       ErrorLog /var/log/apache2/siakad-error_log
       TransferLog /var/log/apache2/siakad-access_log

       #   SSL Engine Switch:
       #   Enable/Disable SSL for this virtual host.
       SSLEngine on

       #   You can use per vhost certificates if SNI is supported.
       SSLCertificateFile /etc/apache2/ssl.crt/sertifikat.crt
       SSLCertificateKeyFile /etc/apache2/ssl.key/kunci.key
       SSLCertificateChainFile /etc/apache2/ssl.crt/chain.crt

       #   Per-Server Logging:
       #   The home of a custom SSL log file. Use this when you want a
       #   compact non-error SSL logfile on a virtual host basis.
       CustomLog /var/log/apache2/ssl_request_log   ssl_combined
       <Directory “/home/taufik/mount-siakad”>
               Options Indexes FollowSymLinks SymLinksIfOwnerMatch
  AllowOverride All
               Require all granted
       </Directory>
</VirtualHost>

</IfDefine>
</IfDefine>

Work till death do me part.

Leave a Reply