1.文件压缩
location ~ .*\.(jpg|gif|png)$ {
gzip on(开启);
gzip_http_version 1.1(版本);
gzip_comp_level 2(压缩比);
gzip_types(文件类型) text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
root /opt/app/code/images;
}
2.压缩gzip文件的预读功能
location ~ ^/download {
gzip_static on(开启);
tcp_nopush on;
root /opt/app/code;
}
3.浏览器缓存原理
location ~ .*\.(htm|html)$ {
add_header Access-Control-Allow-Origin(跨域访问的请求域名) *(表示所有);
add_header Access-Control-Allow-Methods(跨域访问的请求方法) GET,POST,PUT,DELETE,OPTIONS;
expires 24h(缓存周期);
root /opt/app/code;
}
4.静态代理图片和视频示例
server {
listen 8008;
server_name 192.168.160.99;
location /image_video/ {
add_header Access-Control-Allow-Origin *; # 跨域请求域名
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS; # 运行请求
expires 24h; # 缓存时间
root /nas/cloud.shunwang.com/; # 访问路径
autoindex on; # 开启浏览目录权限:autoinedx on,默认是off;
}
}
# http://192.168.160.99:8008/image_video/steam/20/363520/363520_256664103_movie_max.webm 请求地址
# /nas/cloud.shunwang.com/image_video/steam/20/363520/363520_256664103_movie_max.webm 访问地址