Traditional Proxy:The user is hidden behind the proxy server. The proxy server works at the application layer and only forwards the data of the protocols it supports.
Reverse Proxy ):This mechanism is implemented after the Web server is hidden in the proxy server. The server that implements this mechanism is called the reverse proxy server ). In this case, the web server becomes a backend server, and the reverse proxy server is called a front-end server.
One of the purposes of introducing reverse proxy servers is cache-based acceleration. We can cache the content on the reverse proxy server, and the implementation of all caching mechanisms still adopts the HTTP/1.1 protocol.
The reverse proxy server does not use the cache:
Nginx can be used as the reverse proxy server of Apache. When the reverse proxy server does not use the cache, the throughput will decrease. Because the requests that were originally directed to the web are now forwarded by a detour, and the processing time will inevitably increase.
The Web server and Application Server can be separated. The former processes some static content and acts as a reverse proxy, while the latter processes dynamic content.
The reverse proxy server (RPS) uses the cache:
As RPS, varnish can provide better caching functions. If the cached content plays a role, the server displays the backend server in the HTTP Response Header, but the via flag indicates the data source.
RPS can decide which content can be cached and which content cannot be cached by modifying the HTTP header information that flows through it. The browser and the Web server use HTTP to inform RPS of their needs, and RPS coordinates the cache.
Varnish uses the VCL language to modify cache rules through the configuration file. It also provides the ability to forcibly clear the cache. Varnish provides a monitoring program varnishstat to monitor the cache hit rate.
Ideal technical model for cache hit rate and backend throughput:
Actual throughput: the actual throughput when the reverse proxy server processes user requests.
Backend throughput: the throughput of the backend web server when processing requests from the reverse proxy server.
Active Content count: the number of requests requested by the reverse proxy server to the backend server within the average cache validity period.
Cache Loss Rate = (number of active content/(actual throughput × average cache validity) × 100%
Cache hit rate = 1-Cache Loss Rate
Backend throughput = number of active content/average cache Validity Period
Cache hit rate = (1-(backend throughput/actual throughput) × 100%
Backend throughput = (1-Cache hit rate) × actual throughput
Conclusion:
1. When the number of active content and the average cache validity period are fixed, the cache hit rate is proportional to the actual throughput.
2. When the actual throughput and average cache validity are fixed, the cache hit rate is inversely proportional to the number of active content.
3. When the number of active content and actual throughput are fixed, the cache hit rate is proportional to the average cache validity period.
4. When the number of active content is fixed, the backend throughput is inversely proportional to the average cache validity period.
5. When the average cache validity period is fixed, the backend throughput is proportional to the number of active content.
6. Changes in the cache hit rate may not necessarily affect the backend throughput.
7. Changes in the backend throughput may not necessarily affect the cache hit rate.
It can be seen that the higher the cache hit rate, the less the backend server workload is wrong.
ESI (edge side encryption DES)
ESI is similar to SSI. It can embed subpages in pages. Unlike SSI, it assembles content on Web servers. ESI assembles content on HTTP proxy servers, including reverse proxy.
Varnish supports ESI, so varnish supports partial cache of web pages and updates dynamic content locally. Ajax also has similar functions (it supports asynchronous requests for local content ).
Pass through proxy:
The reverse proxy server acts as the intermediary between the user and the backend Web server. It only forwards the user's HTTP request to the backend server. However, some user information is sometimes not in the HTTP request, for example, the user's IP address and the TCP port for sending the request are invisible to the backend web server, so it is necessary to find a way to "pass" the information through the reverse proxy server.
Method: Enable the reverse proxy to carry the additional HTTP header information when requesting the backend server (by configuring the reverse proxy server ). Similarly, if the backend server wants to inform the browser of some additional information, it can also carry custom information in the HTTP response header to "pass through" the reverse proxy.
The advantages of nginx and Lighttpd are mainly reflected in the network I/O model.
Nginx uses the epoll model to provide a high throughput even when the number of concurrent users is large.
For Ajax problems, the local content should be the same as the top-level domain name of the host where the parent page is located.
Factors that affect the cache hit rate: cache expiration time, insufficient cache space to be swapped out, cache granularity, and architecture design.
What factors affect the processing capability of web servers? (Server concurrent processing capability)