Nginx 动静分离提高服务性能
1.动静分离原理和场景: 就是把静态资源在nginx层直接返回去而不是再向后端服务发送请求,快速响应和减少创建链接资源的开销
![](https://img2022.cnblogs.com/blog/1776045/202207/1776045-20220708170331989-2095973091.png)
2.Nginx动静分离配置:
2-1 基础的配置方式:
![](https://img2022.cnblogs.com/blog/1776045/202207/1776045-20220708170331994-1622805738.png)
2-2 正则匹配方式,不用写那么多location:
location ~*/(js|css|img) { # 这里是不区分大小写的,但需要把静态资源上传到nginx服务器上,实际中静态和缓存越靠前性能越好
root html;
index index.html index.htm;
}