I have a Apache web server set which listens on port 4000 and I want to use this (local) server as a kind of proxy.
The idea is to redirect all the local outcomming HTTP traffic (port 80) to my server at 127.0.0.1:4000. Of course, the server must be able to send request on port 80.
I tried to update iptables like this :
iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination 127.0.0.1:4000 Obviously it does not work because the traffic from my server is also redirected to itself.
The question is: how can I only authorize HTTP request from my server?
Example:
- A request is sent to www.google.com
- The request is redirected to my server (
127.0.0.1:4000) - The server receives the request, do some stuff, then sends a request to www.google.com
I managed to do the first part (2.) but because of that my server cannot access www.google.com as it is also redirected to itself.
httpd.conf?iptablesrule earlier than yourDNATrule so that it exits without reaching the DNAT if the source port is the one associated with the proxy?--uid-ownersupposing that's unique to the application doing the proxy.