I try to use iptables to keep Varnish on port 8080 and Apache on port 80 and just preroute everything coming in at port 80 to port 8080. It isn't working. When I call the site on port 8080 everything is cached and fine, when I call it on port 80 I just get the normal Apache response.
So Varnish and Apache seem to be configured correctly, since I receive a cached version on port 8080.
In step 1 I just add the rule to iptables:
#iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
When I then call
#iptables -L -t nat
to see if it worked, I receive this output:
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8080
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
The output from iptables-save:
# Generated by iptables-save v1.4.12 on Mon Oct 27 23:24:03 2014
*raw
:PREROUTING ACCEPT [22819:7234594]
:OUTPUT ACCEPT [32677:42807068]
COMMIT
# Completed on Mon Oct 27 23:24:03 2014
# Generated by iptables-save v1.4.12 on Mon Oct 27 23:24:03 2014
*nat
:PREROUTING ACCEPT [40:2416]
:POSTROUTING ACCEPT [64:3751]
:OUTPUT ACCEPT [64:3751]
-A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
COMMIT
# Completed on Mon Oct 27 23:24:03 2014
# Generated by iptables-save v1.4.12 on Mon Oct 27 23:24:03 2014
*mangle
:PREROUTING ACCEPT [22821:7234698]
:INPUT ACCEPT [22821:7234698]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [32696:42835416]
:POSTROUTING ACCEPT [32696:42835416]
COMMIT
# Completed on Mon Oct 27 23:24:03 2014
# Generated by iptables-save v1.4.12 on Mon Oct 27 23:24:03 2014
*filter
:INPUT ACCEPT [22821:7234698]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [32696:42835416]
COMMIT
# Completed on Mon Oct 27 23:24:03 2014
So it should be fine. What am I missing?? Thanks!