In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
First, the advantages of nginx cache
As shown in the figure, nginx caching can, to some extent, reduce the pressure on the source server to process requests.
Because many static files (such as css,js, pictures) are not updated frequently. Nginx uses proxy_cache to cache user requests to a local directory. The next same request can call the cache file directly, so you don't have to request the server.
After all, the handling of IO-intensive services is nginx's strength.
Second, how to set up
Let's start with a chestnut:
Http {proxy_connect_timeout 10; proxy_read_timeout 180; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 32k; proxy_busy_buffers_size 96k; proxy_temp_file_write_size 96k; proxy_temp_path / tmp/temp_dir; proxy_cache_path / tmp/cache levels=1:2 keys_zone=cache_one:100m inactive=1d max_size=10g; server {listen 80 default_server; server_name localhost; root / mnt/blog/ Location / {} # to cache the suffix of the file, you can set it below. Location ~. *\. (gif | jpg | png | css | js) (. *) {proxy_pass http://ip address: 90; proxy_redirect off; proxy_set_header Host $host; proxy_cache cache_one; proxy_cache_valid 200 302 24h; proxy_cache_valid 301 30d; proxy_cache_valid any 5m; expires 90d; add_header wall "heyworthy guysgiving me a star." }} # blog port server {listen 90; server_name localhost; root / mnt/blog/; location / {}} without nginx cache
Because I was experimenting on a server, I used two ports 80 and 90 to simulate the interaction between the two servers.
Port 80 is connected to ordinary domain name (http://wangxiaokai.vip) access.
Port 90 is responsible for handling resource access from port 80 agents.
Port 90 is the source server and port 80 is the nginx reverse cache proxy server.
Next, let's talk about the configuration items:
2.1 http layer Settings
Proxy_connect_timeout 10; proxy_read_timeout 180; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 32k; proxy_busy_buffers_size 96k; proxy_temp_file_write_size 96k; proxy_temp_path / tmp/temp_dir; proxy_cache_path / tmp/cache levels=1:2 keys_zone=cache_one:100m inactive=1d max_size=10g Timeout of proxy_connect_timeout server connection after successful proxy_read_timeout connection, waiting for back-end server response time proxy_send_timeout backend server data return time proxy_buffer_size buffer size proxy_buffers the number of buffers set for each connection is number, and the size of each buffer is number after enabling the response buffering function for sizeproxy_busy_buffers_size, without reading all responses When the write buffer reaches a certain size, nginx must send a response to the client until the buffer is less than this value. Proxy_temp_file_write_size sets the size (size) that nginx writes data to temporary files each time. Limits the storage path of temporary files received by proxy_temp_path from the back-end server. Proxy_cache_path sets the path and other parameters of the cache. Cached data will be removed from the cache if it is not accessed within the time specified by the inactive parameter (currently 1 day)
2.2 server layer Settings
2.2.1 reverse caching proxy server
Server {listen 80 default_server; server_name localhost; root / mnt/blog/; location / {} # the suffix of the file to be cached can be set below. Location ~. *\. (gif | jpg | png | css | js) (. *) {proxy_pass http://ip address: 90; proxy_redirect off; proxy_set_header Host $host; proxy_cache cache_one; proxy_cache_valid 200 302 24h; proxy_cache_valid 301 30d; proxy_cache_valid any 5m; expires 90d; add_header wall "heyworthy guysgiving me a star." }} if there is no resource in the proxy_pass nginx cache, forward the request to this address, get the new resource, and cache proxy_redirect settings the replacement text proxy_set_header of the back-end server "Location" response header and "Refresh" response header allows you to redefine or add the request header proxy_cache sent to the back-end server to specify the shared memory used for page caching. The keys_zoneproxy_cache_valid corresponding to the http layer sets different cache time for different response status codes, expires cache time.
Here I set up the image, css, js static resources for caching.
When the user enters the http://wangxiaokai.vip domain name, the ip:port access address is obtained by parsing. Port defaults to 80. Therefore, the page request will be intercepted by the current server for request processing.
When the static resource at the end of the above file name is resolved, the static resource is obtained in the cache.
If the corresponding resource is obtained, the data is returned directly.
If not, the request is forwarded to the address pointed to by the proxy_pass for processing.
2.2.2 Source server
Server {listen 90; server_name localhost; root / mnt/blog/; location / {}}
Here, the requests received by port 90 are processed directly, and the resources are crawled in the local directory of the server / mnt/blog to respond.
Third, how to verify whether the cache is valid
Careful readers should find that in the second paragraph of chestnut, I left an egg add_header wall "heyday guysgiving me a star."
Add_header is the information used to set customization in the header.
So, if the cache is valid, then the header returned by the static resource must carry this information.
The results of accessing http://wangxiaokai.vip are as follows:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.