How does reverse proxy server work? Is it used to secure the main server? Is it used as a firewall? What are the reasons for using a proxy server? Could someone give a real world example?
Typically a normal proxy server looks at requests going from an internal network out to the internet and caches them so that if another client requests the same page, the proxy can give it to them much quicker than a brand new request to a remote server.
A reverse proxy works in the opposite way.
Generally a reverse proxy will be installed in front of a web server, so that the second time a client requests a page from that server, the proxy will give it back to the remote client without bothering the web server at all.
In many cases the reverse proxy and the web server are the same machine. This is often done because the work the reverse proxy does is much, much simpler than going through a complete web server transaction.
Apache, lighthttpd and many other web servers can also function as reverse proxies.
Check Wikipedia for more info.
If you are looking for real world implemention in .NET, there is .NET URL Rewriter, a free open-source component for IIS/ASP.NET.
As the name suggests, it's an URL rewriting component, but it has also reverse proxying capabilities.
With a simple line like this in the configuration file
RewriteRule ^(.*) http://www.testsiteXY.com$1 [P]
you could easily distribute sites to internal or external locations.
I could not give a more complete answer then what's available here: http://en.wikipedia.org/wiki/Reverse_proxy
If you are looking for a Java reverse proxy have a look at Membrane Monitor and Router.