To forward port 80 with Apache, add the following to your Apache configuration file.
If you’re using WHM, simply use the include editor.
<VirtualHost 203.0.113.0:80>
ProxyPass / http://203.0.113.0:2368/ nocanon
ProxyPassReverse / http://203.0.113.0:2368/
ProxyRequests Off
AllowEncodedSlashes NoDecode
<Proxy http://203.0.113.0:2368/*>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
In this example, 203.0.113.0
is the IP of your server, and 2368
is the port you’re forwarding to. All traffic from 203.0.113.0:80 will now be forwarded to 203.0.113.0:2368.
Blocking direct access to the target port
If you’d like to prevent direct access to the target port (2368
in this example), you can add the following firewall rules to iptables.
# Block incoming TCP traffic to port 2368.
iptables -I INPUT -p tcp --dport 2368 -j DROP
# Allow proxy access to port 2368.
# These are all the rules necessary to allow traffic through.
# (Regardless of the existing INPUT/OUTPUT chain policies)
iptables -I INPUT -s 203.0.113.0 -p tcp --dport 2368 -j ACCEPT
iptables -I INPUT -s 203.0.113.0 -p tcp --sport 2368 -j ACCEPT
iptables -I OUTPUT -s 203.0.113.0 -p tcp --dport 2368 -j ACCEPT
iptables -I OUTPUT -s 203.0.113.0 -p tcp --sport 2368 -j ACCEPT