iptables preroute localhost
Instead of doing -d 127.0.0.1
on the OUTPUT rule, you could do -o lo
. This will match any traffic going through the loopback interface no matter what the destination is.
As a side note, even when you send to 'http://myserver:443', the traffic is still local, so it still goes through the loopback interface, even though it doesnt resolve to '127.0.0.1'.