Yesterday J. L asked me how to set the HTTP cache, the brain was a bit confused, a moment unexpectedly he asked is how the reverse proxy set.
Starter: PHP CUP Xiaobao
What is a reverse proxy?
A reverse proxy is a special feature of a proxy server, such as Isa, Squid, which speeds up the ability of customers to access your Web server. Do you have a forward proxy? Yes, forward proxy it also speeds up the user's access to the Web server. What is the difference between the two? This understanding, using the Proxy server forward proxy function, the agent is your intranet users access to any Web server on the Internet, and the use of Proxy server reverse proxy function, is the proxy from any customer on the Internet to access your intranet Web server.
What is the principle of gallop?
You may be surrounded by running insurance, bank cards, cosmetics marketing people, these people are agents of the enterprise, you do not have to run to the bank to handle the bank card, because the bank agent caches the bank need you fill in some of the documents, in fact, this is the process of the forward agent. In turn, you are also selling your own hand knitting sweaters, then these people can also as your agent, when there is a public need, do not have to contact you directly, because the agent in advance to cache the sweater you want to sell, this business for the agent is the reverse proxy process. So how does the reverse proxy speed up your sweater service?
Figure, three reverse proxy server is just mentioned run insurance, bank card, cosmetics salesman, firewall inside the server is you. You distribute the knitted sweater to these 3 people beforehand, so that they share your busy sweater service. Reflecting reality, we can use multiple proxy servers to handle requests for a high-volume content server, and the benefit is that content servers can handle higher loads and are more efficient than when they are working alone. During the initial boot, the proxy server retrieves the document from the content server for the first time, after which the majority of requests from the customer are returned directly to the cache server, reducing the number of requests to the content server.
Special note: New requests and CGI requests must go all the way to the content server, and the remaining requests can be processed directly by the proxy server. It is obvious that a new request must first reach the content server, otherwise cache what content? A CGI request is a request for a dynamically changing page, such as the article page you are looking at can be changed at any time due to the use of replies, reverse proxy generally do not cache the content page of this request.
How do I configure a reverse proxy?
Proxy Server software that generally provides caching capabilities can be configured with reverse proxy functionality, such as Microsoft Isa, or squid under Linux, this article takes squid as an example, both principles.
Configuring the reverse proxy with squid is primarily the squid.conf configuration file. If you use the system's own squid package, the configuration file/etc/Squid/Directory.
1, single squid reverse proxy server<==>A single Web server
Vi/etc/Squid/Squid.conf
Http_port80
Httpd_accel_host172.10.1.1
Httpd_accel_port80
Httpd_accel_single_host on
Httpd_accel_with_proxy on
directive function:
Http_port, specifies the port on which squid listens for HTTP requests, typically set to port 80, so that the user does not feel the presence of a reverse proxy, just like accessing a real Web server. For example, the user does not need to be in the browser to typing http://www.phpcup.cn:8080, enter HTTP directly as before://The www.phpcup.cn will be ready.
Httpd_accel_host, specifies the listening port for the Web server.
Httpd_accel_host, specify the IP address of the Web server.
Httpd_accel_single_host, when command httpd_accel_single_host is on, squid is set to reverse proxy only for a single Web server. That is, a reverse proxy server can not only provide services for a single Web content server, but also serve multiple services at the same time. This command is set to OFF when squid provides a reverse proxy for multiple Web servers.
Httpd_accel_with_proxy, if you want squid to be both a reverse proxy server and a forward proxy server for the Internet on the local machine, you need to set this command to ON.
2, multiple squid reverse proxy server<==>A single Web server
Squid reverse proxy configuration such as (1As described, what you need to do now is look at the configuration of the DNS server. We know that the user entered in the browser is the host name, not the IP address, but the computer network device must know the IP address to communicate, which requires a DNS server to implement host name to IP address conversion, more detailed working principle can access the PHP CUP.
Now all we have to do is to implement polling on multiple squid reverse proxies on the DNS server. Polling is the return of 123 when the first user requests the IP address of a phpcup.cn.123.123.1, and the next returns 123.123.123.2, and the next request from the user returns 123.123.123.3, so that the public IP of 3 squid servers is displayed to the user by DNS server. Regardless of which DNS server software is used to match, its database is the same:
www.phpcup.cn. In A123.123.123.1
www.phpcup.cn. In A123.123.123.2
www.phpcup.cn. In A123.123.123.3
It can be seen that a resource record of a host name corresponds to the address of several squid reverse proxy servers, which realizes the polling effect.
Special note: For DNS servers, you can set the polling method to resolve the stress inequality issue. With Bind9. X For example, modify its configuration file named.conf
Options {
RRset-order {order cyclic;};
};
RRset-The order command has three optional parameters: random,fixed Random, randomly returns the IP address of a record
fix, Fixed multiple A records in the order of configuration files to
cyclic, looping back the IP address of a record
We need exactly cyclic,round-robin (polling) mode, with 1->2 ->3->1->2 ... Answer the user's request in such a way.
Restart the bind service /etc /init.d/named reload
uses dig www.phpcup.cn to track whether the polling configuration of the DNS server is in effect.
Reverse Proxy--Accelerator for Web services [go]