本案例基于Windows环境,Linux类似
1.nginx下载
2.配置,解压nginx,配置根路径 conf/nginx.conf。
a.在[http]节点下开起gzip资源压缩
gzip on;
gzip_min_length 1k;
#压缩等级:1-9
gzip_comp_level 6;
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 application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
gzip_buffers 32 4k;
b.配置静态资源。
在[http->server]节点下增加[location]节点,如下
location /images {
#允许跨域
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Headers DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type;
add_header Access-Control-Max-Age 1728000;
#静态资源根文件夹
alias images-resources;
}
加入服务端口为80,images-resources根文件夹下的图片为hello.jpg,则访问:http://localhost/imeges/hello.jpg即可访问到资源