Nginx服务系列——静态资源web服务
传输
sendfile on | off;默认off(http\server\location\if in location) tcp_nopush on | off;默认off(http\server\location)sendfile开启的情况下,提高网络包的传输效率 tcp_nodelay on | off;默认on(http\server\location)keepalive连接下,提高网络传输的实时性
压缩文件
gzip on | off;默认off(http\server\location\if in location) 压缩传输 gzip_comp_level level;默认level=1(http\server\location) 压缩等级 gzip_http_version 1.0 | 1.1;默认1.1(http\server\location) gzip_types text/plain被压缩的格式
扩展nginx压缩模块
http_gzip_static_modele 预读gzip功能(通过文件名调用相应的gz压缩包)
gzip_static on;
浏览器进行缓存校验(ETag/Last-Modified)验证会返回304
expires: 24h;在响应头中添加Cache-control:max-age=86400并返回expires头
跨站:
add_header name value(http\server\location\if in location) 如:add_header Access-Control-Allow-Origin 域名;
防盗链:(防止资源被盗用)
http_refer
valid_referers none | blocked | server_names | string ...;(server\location) 如:valid_referers none blocked 域名;域名可以使用匹配的方式设置,~ if($invalid_referer){ return 403; }