Linux Iptables Setup Firewall For a Web Server

Originally published at: https://www.cyberciti.biz/faq/linux-web-server-firewall-tutorial/

I have setup an Apache web server on CentOS Linux. How do I configure firewall to allow or block access? How do I setup firewall for a web server under RHEL or CentOS Linux v6.x or 7.x?