Implementing Reverse Proxy in Squid
Introduction
This document describes reverse proxies, and how they are used to improve Web server performance. Section 1 gives an introduction to reverse proxies, describing what they are and what they are used for. Section 2 compares reverse proxy caches with standard and transparent proxy caches, explaining the different functionality each provides. Section 3 illustrates how the reverse proxy actually caches the content and delivers it to the client. Section 4 describes how to configure Squid as a reverse proxy cache.
What is reverse proxy cache
Reverse proxy cache, also known as Web Server Acceleration, is a method of reducing the load on a busy web server by using a web cache between the server and the internet. Another benefit that can be gained is improved security. It's one of many ways to improve scalability without increasing the complexity of maintenence too much. A good use of a reverse proxy is to ease the burden on a web server that provides both static and dynamic content. The static content can be cached on the reverse proxy while the web server Will Be FREED UP TO BETTER HANDLE The DYNAMIC Content.
By Deploying Reverse Proxy Server Alongside Web Servers, Sites Will:
Avoid The Capital Expense of Purchasing Additional Web Servers by Increasing The Capacity of Existing Servers.
Serve More Requests for Static Content from Web Servers.
Serve More Requests for Dynamic Content from Web Servers.
Increase Profitability of the Business By Reducing Operating Expenses Including The Cost of Bandwidth Required To Serve Content.
Accelerate The Response Time of Web and Accelerate Page Download Times To End Uses, Delivering A Faster, Better Experience To Site Visitors.
When planning a Reverse-Proxy implementation the origin server's content should be written with the proxy server in mind, ie it should be "Cache Friendly". If the origin server's content is not "cache aware", it will not be able to take full advantage of the reverse proxy cache.In Reverse Proxy mode, the Proxy Server functions more like a web server with respect to the clients it services. Unlike internal clients, external clients are not reconfigured to access the proxy server. Instead, the site URL routes the client to the proxy as if it were a web server. Replicated content is delivered from the proxy cache to the external client without exposing the origin server or the private network residing safely behind the firewall. Multiple reverse proxy servers can be used to balance the Load on an over-Taxed Web Server In Much The Same Way.
The objective of this white paper is to explain the implementation of Squid as a Reverse-proxy also known as Web Server-accelerator. The basic concept of caching is explained followed by the actual implementation and testing of the reverse-proxy mode of squid.
About Squid
Squid is an Open source high-performance Proxy caching server designed to run on Unix systems. National Science Foundation funds squid project, Squid has its presence in numerous ISP's and corporate around the globe. Squid can do much more than what most of the proxy servers Around Can do.
Squid supports ....
Proxying and caching of http, ftp, and other urls
Proxying for SSL
Cache hierarchies
ICP, HTCP, CARP, AND Cache Digests
TRANSPARENT CACHING - WCCP
Extensive Access Controls
HTTP Server Acceleration
SNMP
Caching of dns lookups.
Reverse Proxy Compared with Other Proxy Caches
There Are Three Main Ways That Proxy Caches Can Be Configured ON A Network:
Standard Proxy Cache
A standard proxy cache is used to cache static web pages (html and images) to a machine on the local network. When the page is requested a second time, the browser returns the data from the local proxy instead of the origin web server. The .
TRANSPARENT CACHE
A transparent cache achieves the same goal as a standard proxy cache, but operates transparently to the browser. The browser does not need to be explicitly configured to access the cache. Instead, the transparent cache intercepts network traffic, filters HTTP traffic (on port 80 ), and handles the request if the item is in the cache. If the item is not in the cache, the packets are forwarded to the origin web server. For Linux, the transparent cache uses iptables or ipchains to intercept and filter the network traffic . Transparent caches are especially useful to ISPs, because they require no browser setup modification. Transparent caches are also the simplest way to use a cache internally on a network (at peering-hand off points between an ISP and a larger ~ network, for example ), Because They Don't Require Explicit Coordination With Other Caches.
Reverse Proxy Cache
A reverse proxy cache differs from standard and transparent caches, in that it reduces load on the origin web server, rather than reducing upstream network bandwidth on the client side. Reverse Proxy Caches offload client requests for static content from the web server, preventing unforeseen traffic surges from overloading the origin server. The proxy server sits between the Internet and the Web site and handles all traffic before it can reach the Web server. A reverse proxy server intercepts requests to the Web server and instead responds to the request out of a store Of Cached Improves The Performance by Reducing The Amount of Pages Actually Created "Fresh" by The Web Server.how Reverse Proxy Caches Work
A Reverse Proxy Is posiented Between The Internet and The Web Server
When a client browser makes an HTTP request, the DNS will route the request to the reverse proxy machine, not the actual web server. The reverse proxy will check its cache to see if it contains the requested item. If not, it connects to the Requested Item To ITS Disk Cache. The Reverse Proxy CaN Only Server Cacheable Urls (SUCH AS HTML PAGES AND m).
Dynamic Content Such As CGI Scripts and Active Server Pages Cannot Be Cached. The Proxy Caches Static Page.
The Four Most Important Header Tags Are:
Last-Modified: Tells The Proxy when Page Was Last Modified.
EXPIRES: TELLS The Proxy When to Drop The page from the cache.
Cache-Control: Tells the proxy if the page shop be cached.
Pragma: Also Tells The Proxy If The page shop be cached.
For example, by default all Active Server Pages return "Cache-control:. Private" Therefore, no Active Server Pages will be cached on a reverse proxy server.Configuring Squid as Reverse Proxy (http accelerator)
To set up Squid as an httpd accelerator, you simply configure the squid.conf file. Usually it is found in either / usr / local / squid / etc, when installed directly from source code, or / etc / squid when pre-installed on Red Hat Linux systems. The squid.conf file is used to set and configure all the different options for the Squid proxy server. As root open the squid.conf file in your favorite text editor. If the real web server runs on a separate machine Than The Squid Reverse Proxy, Edit The Following Options in The Squid.conf File:
HTTP_PORT 80 # Port of Squid Proxy
httpd_accel_host 172.16.1.115 # ip address of Web Server
HTTPD_ACCEL_PORT 80 # Port of Web Server
httpd_accel_single_host on # Forward Uncached Requests to Single Host
HTTPD_ACCEL_WITH_PROXY ON #
HTTPD_ACCEL_USES_HOST_HEADER OFF
IF The Web Server Runs On The Same Machine WHERE Squid IS Running, The Web Server Daemon Must Be Set To Run On Port 81 (or any Other Port Than 80). With the apache web server, it can done by assigning the line "Port" Port 80 "to" port 81 "in its httpd.conf file. The Squid.conf Must Also Be Modified to Redirect Missed Requests to Port 81 of the Local Machine:
HTTP_PORT 80 # Port of Squid Proxy
HTTPD_ACCEL_HOST LOCALHOST # ip address of Web Server
HTTPD_ACCEL_PORT 81 # Port of Web Server
httpd_accel_single_host on # Forward Uncached Requests to Single Host
HTTPD_ACCEL_WITH_PROXY ON #
HTTPD_ACCEL_USES_HOST_HEADER OFF
We Describe these options in Greater Detail.
HTTP_PORT 80
The option http_port specifies the port number where Squid will listen for HTTP client requests. If this option is set to port 80, the client will have the illusion of being connected to the actual web server. This options should always be port 80.httpd_accel_host 172.16 .1.115 and httpd_accel_port 80
The options httpd_accel_host and httpd_accel_port specify the IP address and port number of the real HTTP Server, such as Apache. In our configuration, the real HTTP Web Server is on the IP address 172.16.1.115 and on port 80.
If we are using the reverse proxy for more than one web server, then we must use the word virtual as the httpd_accel_host. Uncached requests can only be forwarded to one port. There is no table that associates accelerated hosts and a destination port. When the Web Server Is Running on The Same Machine As Squid, Set The Web Server To Listen for Connections ON A Different Port (8000, for Example), and set the httpd_accel_port option to the Same Value.
HTTPD_ACCEL_SINGLE_HOST ON
To run Squid with a single back end web server, set httpd_accel_single_host option to on. Squid will forward all uncached requests to this web server regardless of what any redirectors or Host headers says. If the Squid reverse proxy must support multiple back end web servers, set this option to off, and use a redirector (or host table or private DNS) to map the requests to the appropriate back end servers. Note that the mapping needs to be a 1-1 mapping between requested and backend (from redirector) domain .
HTTPD_ACCEL_WITH_PROXY ON
If one wants to use Squid as both an httpd accelerator and as a proxy for local client machines, set the httpd_accel_with_proxy to on. By default, it is off. Note however that your proxy users may have trouble reaching the accelerated domains, unless their browsers Are Configured Not to Use The Squid Proxy for Those Domains. The No_Proxy Option Can Be Used To Direct Clients Not To Use The Proxy for Certain Domains.httpd_accel_uses_host_header OFF
Requests in HTTP version 1.1 include a Host header, specifying the host name (or IP address) of the URL. This option should remain off in reverse proxy mode. The only time this option must be set to on is when Squid is configured as a TRANSPARENT PROXY.
It's important to note that acls (access control lists) are checked before this translation. You must combine this option with strict source-address checks, so you can not use this option to accelerate multiple back end servers.
Configuring Squid AS Reverse Proxy for Multiple Domains (HTTP Accelerator)
You can configure Squid in an accelerator model for multiple domains also. For example You can at www.abc.com, www.xyz.com, www.lmn.com.
Squid Configuration
HTTPD_ACCEL_HOST VIRTUAL
HTTPD_ACCEL_PORT 80 (The Web Server Port)
HTTPD_ACCEL_SINGLE_HOST OFF (IT SHOULD BE DISABLED WHEN WHEN WHEN WHEN WEY "
HTTPD_ACCEL_USES_HOST_HEADER ON
NOTE: WHEN YOU Compile Squid Enable The Internal DNS Option
To set the reverse proxy for the domain
Www.abc.com 192.168.1.2
Www.xyz.com 192.168.1.2
Www.lmn.com 192.168.1.2
Let Reverse_Proxy Server IP BE 192.168.1.2
DNS Entry In The Reverse Proxy Server
You need to configure Intranet DNS and Internet DNS. You can configure split DNS if you want both the DNS in same machine. Instead of Intranet DNS you can have domain entries in / etc / hosts. You have to configure squid with --disable- Internal-DNS to use / etc / hosts file look.internal DNS Entry
Www.abc.com in A 172.16.1.2
Www.xyz.com in a 172.16.1.3
Www.lmn.com in a 172.16.1.4
NOTE: IF you have compiled with disable in security DNS, THEN add the entry in the / etc / hosts like
172.16.1.2 www.abc.com
172.16.1.3 www.xyz.com
172.16.1.4 www.lmn.com
Internal DNS Entry
Www.abc.com 192.168.1.2
Www.xyz.com 192.168.1.2
Www.lmn.com 192.168.1.2
References
The Squid FAQ Site
The Visolve Squid Configuration Manual
Conclusion
Reverse proxying is a special proxy deployment used to reduce load on a web server. The reverse proxy server is placed outside the firewall, acting as the web server to external clients. Cached requests are sent back directly to the clients without any computation from the actual Web Server. Uncached Requests Must Be Forwarded To The Backend Web Server, And The Response from The Web Server Is The Response from The Reverse Proxy.
About Visolve.com
ViSolve is an international corporation that provides technical services, for Internet based systems, for clients around the globe. ViSolve is in the business of providing software solutions since 1995. We have experience of executing several major projects and we are now completely focused on leading Internet Technologies, Testing Qa and Support. We are committed to the open source movement and in the Same Lines We provide Free Support for Products Like Linux, Apache and Squid to the user community.