06-06-2019, 05:39 AM
It can be done via the firewall without any changes to the web server.
Try the rule above. Don't forget to change the <new port here> part to the port that you want to redirect to.
An alternative:
Here again make sure you adjust <new port here> and also <your server ip>.
If the server is OpenVZ and doesn't have the NAT iptables modules loaded on the hostnode the commands might fail. In that case you might have to build a vHost on port 80 that redirects to the other port. For that take a look at this: https://stackoverflow.com/a/13089668
My references for the iptable rules:
- https://www.cyberciti.biz/faq/linux-port...-iptables/
- https://wiki.debian.org/Firewalls-local-...edirection
P.S.: "throw"? You mean "to". Throw means absolutely something different.
Code: (Select All)
iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports <new port here>
Try the rule above. Don't forget to change the <new port here> part to the port that you want to redirect to.
An alternative:
Code: (Select All)
iptables -t nat -I PREROUTING --src 0/0 --dst <your server ip> -p tcp --dport 80 -j REDIRECT --to-ports <new port here>
Here again make sure you adjust <new port here> and also <your server ip>.
If the server is OpenVZ and doesn't have the NAT iptables modules loaded on the hostnode the commands might fail. In that case you might have to build a vHost on port 80 that redirects to the other port. For that take a look at this: https://stackoverflow.com/a/13089668
My references for the iptable rules:
- https://www.cyberciti.biz/faq/linux-port...-iptables/
- https://wiki.debian.org/Firewalls-local-...edirection
P.S.: "throw"? You mean "to". Throw means absolutely something different.