008.Nginx静态资源
一 Nginx静态资源概述
1.1 静态资源类型
类型
|
种类
|
|
浏览器端渲染
|
HTML、CSS、JS
|
|
图片
|
JPEG、GIF、PNG
|
|
视频
|
FLV、MP4
|
|
文件
|
TXT及其他类型文件
|
1.2 静态资源场景


二 静态资源优化配置
2.1 sendfile
1 location /mp3 {
2 #...
3 sendfile on;
4 sendfile_max_chunk 1m;
5 #...
6 }
2.2 tcp_nopush
1 location /mp3 {
2 #...
3 sendfile on;
4 tcp_nopush on;
5 #...
6 }
2.3 tcp_nodelay
1 location /mp3 {
2 #...
3 tcp_nodelay on;
4 keepalive_timeout 65;
5 #...
6 }
三 静态资源压缩选项
3.1 gzip压缩配置
1 location /mp3 {
2 #...
3 gzip on;
4 #...
5 }
3.2 gzip压缩比配置
1 location /mp3 {
2 #...
3 gzip on;
4 gzip_comp_level 6;
5 #...
6 }
3.3 gzip压缩协议版本配置
1 location /mp3 {
2 #...
3 gzip on;
4 gzip_comp_level 6;
5 gzip_http_version 1.1;
6 #...
7 }
3.4 gzip预压缩配置
1 location /mp3 {
2 #...
3 gzip_static on;
4 gzip_proxied expired no-cache no-store private auth;
5 #..
6 }
3.5 gzip_buffers压缩缓冲配置
1 location /mp3 {
2 #...
3 gzip_buffers 32 4k
4 #...
5 }
3.6 gzip_disable例外配置
1 location /mp3 {
2 #...
3 gzip on;
4 gzip_buffers 4 16k;
5 gzip_comp_level 2;
6 gzip_disable "MSIE [1-6]\.";
7 #...
8 }
3.7 gzip_min_length特定的大小压缩配置
1 location /mp3 {
2 #...
3 gzip on;
4 gzip_buffers 4 16k;
5 gzip_min_length 1k;
6 gzip_comp_level 2;
7 gzip_disable "MSIE [1-6]\.";
8 #...
9 }
3.8 gzip_types压缩类型配置
1 location /myhome {
2 #...
3 gzip on;
4 gzip_min_length 1k;
5 gzip_buffers 4 16k;
6 gzip_comp_level 2;
7 gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
8 gzip_disable "MSIE [1-6]\.";
9 #...
10 }
3.9 gzip_proxied反向代理压缩配置
四 静态资源压缩配置
4.1 创建站点目录

4.2 配置虚拟主机
1 [root@nginx ~]# vi /etc/nginx/conf.d/gzip.conf
2 server {
3 listen 80;
4 server_name gzip.linuxds.com;
5 sendfile on;
6 access_log /var/log/nginx/gzip.access.log main;
7 error_log /var/log/nginx/gzip.error.log warn;
8 location / {
9 root /usr/share/nginx/gzip;
10 index index.html;
11
12 gzip on;
13 gzip_min_length 1k;
14 gzip_buffers 4 16k;
15 gzip_http_version 1.1;
16 gzip_comp_level 2;
17 gzip_disable "MSIE [1-6]\.";
18 gzip_types text/plain application/json application/x-javascript application/javascript text/css application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif imag
19 e/png;
20 }
21 }
1 [root@nginx ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件
2 [root@nginx ~]# nginx -s reload #重载配置文件
4.3 确认验证
1 [root@imxhy ~]# curl -I -H "Accept-Encoding: gzip, deflate" "http://gzip.linuxds.com/css/test.css"
2 [root@imxhy ~]# curl -I -H "Accept-Encoding: gzip, deflate" "http://gzip.linuxds.com/images/test.jpeg"
3 [root@imxhy ~]# curl -I -H "Accept-Encoding: gzip, deflate" "http://gzip.linuxds.com/js/test.js"

008.Nginx静态资源的更多相关文章
- 清除nginx静态资源缓存
之前写过一篇如何配置nginx缓存及手动清除缓存的文章: http://www.cnblogs.com/Eivll0m/p/4921829.html 但如果有大量缓存需要清理,手动一条条清理就比较慢了 ...
- Nginx 静态资源缓存配置
示例 # Media: images, icons, video, audio, HTC location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|m ...
- Nginx——静态资源服务器(一)
java web的项目中,我们经常将项目部署到Tomcat或者jetty上,可以通过Tomcat或者jetty启动的服务来访问静态资源.但是随着Nginx的普及,用Nginx来作为静态资源服务器,似乎 ...
- nginx静态资源设置缓存的方法
nginx静态资源设置缓存的方法 直接加expires 30d; 就是就可以了 缓存时间30天完整如下 <pre> location / { root /home/www/wordpres ...
- 06 . Nginx静态资源缓存
Nginx静态资源 Nginx可以处理静态资源 非Web服务器可以运行处理而生成的文件,即服务器只需要从硬盘或者缓存中读取然后直接给客户端响应即可. 常见的静态资源 # 浏览器渲染: html文件,样 ...
- nginx静态资源分离部署
修改nginx.conf文件,用于nginx处理静态资源. 主要配置如下(在server配置中加入location配置即可): server { listen 80; server_name 123. ...
- Nginx详解十:Nginx场景实践篇之Nginx静态资源场景配置
一.静态资源WEB服务 1.静态资源类型:非服务器动态运行生成的文件 2.静态资源服务场景-CDN 假设静态资源存储中心在云南,用户在北京去请求一个文件,那么就会造成一个传输的延时,而如果Nginx同 ...
- nginx静态资源缓存策略配置
1. 问题-背景 以前也经常用nginx,但用的不深,通常是简单的设置个location用来做反向代理.直到今天给客户做项目碰到缓存问题:客户有个app,只是用原生做了个壳,里面的内容都是用h5写的, ...
- nginx静态资源缓存与压缩
一.静态资源缓存 参考文章 (1)apache设置max-age或expires 这里需要修改.htaccess文件. <IfModule mod_headers.c> <Files ...
随机推荐
- 附015.Kubernetes其他技巧
一 优化镜像源 1.1 国内镜像源 global proxy in China format example dockerhub (docker.io) dockerhub.azk8s.cn dock ...
- 科学计算:Python 分析数据找问题,并图形化
对于记录的数据,如何用 Python 进行分析.或图形化呢? 本文将介绍 numpy, matplotlib, pandas, scipy 几个包,进行数据分析.与图形化. 准备环境 Python 环 ...
- tcpdump抓包工具的基本使用
为了更好的深入理解计算机网络等相关知识,例如TCP\UDP\IP等,我们就必须利用tcpdump.Wireshark等工具对网络进行分析.本篇博文主要记录一下tcpdump这个网络分析利器的一些基本使 ...
- C# 加密、解密PDF文档(基于Spire.Cloud.SDK for .NET)
Spire.Cloud.SDK for .NET提供了接口PdfSecurityApi可用于加密.解密PDF文档.本文将通过C#代码演示具体加密及解密方法. 使用工具: Spire.Cloud.SDK ...
- Mac App 破解之路八 病毒程序分析
本人使用MacBooster 7 扫出了几个未知程序. JMJ56 这个程序. 在finder中打开发现是一个shell脚本 调用了python 9NKb0 就是python脚本使用. 只不过是 ...
- 学习 SQL Server (5) :视图,索引,事务和锁+T_SQL
--=============== 视图的创建 =================. --create view 视图名 as 查询语句--注意:视图查询中的字段不能重名-- 视图中的数据是‘假数据’ ...
- Jmeter之仿真高并发测试-集合点
场景: 大家在使用Jmeter测试的时候应该发现了, (1)线程启动了就会直接发送测试请求:--如果要模拟在一瞬间高并发量测试的时候,需要调高线程数量,这很耗测试机器的性能,往往无法支持较大的并发数, ...
- junit配合catubuter统计单元测试的代码覆盖率
1.视频参考孔浩老师ant视频笔记 对应的build-junit.xml脚步如下所示: <?xml version="1.0" encoding="UTF-8&qu ...
- 05[掌握]高可用、集群、持久化、docker 等前置知识点
高可用 24小时对外提供服务 高并发 同一时间段能处理的请求数 1,中心化和去中心化 1.1,中心化 意思是所有的节点都要有一个主节点 缺点:中心挂了,服务就挂了 中心处理数据的能力有限,不能把节点性 ...
- 使用 nuget server 的 API 来实现搜索安装 nuget 包
使用 nuget server 的 API 来实现搜索安装 nuget 包 Intro nuget 现在几乎是 dotnet 开发不可缺少的一部分了,还没有用过 nuget 的就有点落后时代了,还不快 ...

