静态资源类型
非服务器动态运行生成的文件
浏览器端渲染:(HTML.CSS,JS图片JPEG GIF PNG视频文件
静态资源服务场景-CDN
文件读取配置语法
语法 sendfile on|off
默认值:sendfile off
Context:http,server,location
tcp_nopush 一次性发送
语法 tcp_nopush on|off
默认值 tcp_nopush off
Context:http,server,location
tcp_nodelay 实时发送
语法 tcp_nodelay on|off
默认值 tcp_nodelay on;
Context:http,server,location
需要在http1.1 keeplive 长连接下

压缩传输 gzip

  1. 语法:gzip on|off
  2. 默认 gzip off
  3. Context:http,server,location

扩展Nginx 压缩模块

http_gzip_static_module 预读取gzip功能

静态资源web服务

  1. server {
  2. listen 8080;
  3. sendfile on;
  4. access_log /usr/local/nginx/logs/static_access.log;
  5. gzip on;
  6. gzip_http_version 1.1;
  7. gzip_comp_level 2;
  8. gzip_types text/plain image/jpeg image/gif image/png application/xml text/javascript application/javascript;
  9. location ~ .*\.(jpg|gif|png)$ {
  10. root /data/static/images;
  11. }
  12. location ~ .*\.(txt|xml)$ {
  13. root /data/static/doc;
  14. }
  15. location ~ ^/download {
  16. gzip on;
  17. tcp_nopush on;
  18. root /data/static/download;
  19. }
  20. }

读取图片资源

  1. scp ~/Downloads/heidong.png root@192.168.1.120:/data/static/images/

关闭压缩
image.png
开启压缩

image.png

异步文件读取

with-file-aio