Nginx cache configuration and use

1 Normal cache

1.1 Browser cache

  • Accelerate user access and improve the experience of a single user (browser visitor), cached locally
  • Users can clear the data by clearing the browser cache

1.2 Nginx cache

  • Cache on the Nginx side, promote all users who access to the nginx side
  • Improve the speed of accessing upstream servers
  • User visits will still generate request traffic

1.3 Control browser cache

location /files {
	alias /opt/module/cache;
	# expires 10s;
	# expires @22h30m;
	# expires -1h;
	# expires epoch;
	# expires off;
	expires max;
}
<html>
	<body>
			<h1>
				Hello, EveryOne ~ !~
			</h1>
	</body>
</html>

2 Reverse proxy cache

# proxy_cache_path 设置缓存目录
# keys_zone 设置共享内存以及占用空间大小
# max_size 设置缓存大小
# inactive 超过此时间则被清理
# use_temp_path 临时目录,使用后会影响nginx性能
proxy_cache_path /usr/local/nginx/upstream_cache keys_zone=mycache:5m max_size=1g inactive=30ms  use_temp_path=off;
location / {
	proxy_pass http://tomcats;
	# 启用缓存,和keys_zone一致
	proxy_cache mycache;
	# 针对200和304状态码缓存时间为8小时
	proxy_cache_valid 200 304 8h;
}

3 Related information

  • The blog post is not easy, everyone who has worked so hard to pay attention and praise, thank you

Guess you like

Origin blog.csdn.net/qq_15769939/article/details/113429438