Implementing reverse proxy in squid

Source: Internet
Author: User
Tags dns entry squid proxy
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. section 2 compares reverse proxy caches with standard and transparent proxy caches, explaining the different functionality each provides. section 3 analyze strates 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 loading 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 several ways to improve scalability without increasing the complexity of maintenence too much. A good use of a reverse proxy is to handle 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 allocation cing expenses including the cost of bandwidth required to serve content.

Accelerate the response time of Web and accelerate page download times to end users, delivering a faster, better experience to site visitors.

When planning a reverse-proxy implementation the origin server's content shoshould be written with the proxy server in mind, I. e. it shoshould 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 adjust ate 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 browser is explicitly configured to direct all HTTP requests to the proxy cache, rather than the target Web server. the cache then either satisfies the request itself or passes on the request to the target server.

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 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 uses CES load on the Origin web server, rather than bandwidth cing 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 pages. this method improves the performance by tuning the amount of pages actually created "fresh" by the Web server.

How reverse proxy caches work

A reverse proxy is positioned 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 real Web server and downloads the requested item to its disk cache. the reverse proxy can only server cacheable URLs (such as HTML pages and images ).

Dynamic content such as CGI scripts and Active Server Pages cannot be cached. The proxy caches static pages based on HTTP header tags that are returned from the web page.

The four most important header tags are:

Last-modified: tells the proxy when the page was last modified.

Expires: tells the proxy when to drop the page from the cache.

Cache-control: tells the proxy if the page shocould be cached.

Pragma: Also tells the proxy if the page shoshould 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.

Grouping 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 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 impact of being connected to the actual Web server. this options shoshould 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 ctor) domain names or caching will fail, as caching is already med using the URL returned from the redirector ctor. see also rewrites_host_header.

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 shoshould 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 cannot use this option to accelerate multiple back end servers.

Grouping squid as reverse proxy for multiple domains (HTTP accelerator)

You can configure squid in an accelerator mode for multiple domains also. For example you can configure single squid machine for 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 shocould be disabled when we are going to the reverse proxy for multiple servers)

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 lookup.

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 internal 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 then cached in 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.