Question

 How to redirect plain HTTP request to Versa Director to HTTPS automatically?



Solution

This is achieved by adding these two entries in /etc/rc.local file:


iptables-t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

iptables-t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 8080


NOTE: sudo permission is required to edit the file.

 

Sample Config File (/etc/rc.local)


#!/bin/sh-e
#
#rc.local
#
# Thisscript is executed at the end of each multiuser runlevel.
# Makesure that the script will "exit 0" on success or any other
# valueon error.
#
# Inorder to enable or disable this script just change the execution
# bits.
#
# Bydefault this script does nothing.

iptables-t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
iptables-t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 443 -j REDIRECT --to-ports 8443
ip6tables-t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
ip6tables-t nat -I OUTPUT -p tcp -d ::1 --dport 443 -j REDIRECT --to-ports 8443
iptables-t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables-t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 8080
==================================================================