#一、静态资源Web服务
#文件读取
Syntax: sendfile on|off;
Default : sendfile off;
Context:http,server,location,if in location
#tcp_nopush配置语法
#作用:sendfile开启的情况下,提供网络包的传输效率
Syntax: tcp_nopush on|off;
Default : tcp_nopush off;
Context:http,server,location
#tcp_nodelay配置语法
#在keepalive连接下,提高网络包的传输实时性
Syntax: tcp_nodelay on|off;
Default : tcp_nodelay off;
Context:http,server,location
#gzip配置语法
#作用:压缩传输
Syntax: gzip on|off;
Default : gzip off;
Context:http,server,location,if in location
#压缩比
Syntax: gzip_comp_level level;
Default : gzip_comp_level level 1;
Context:http,server,location
#版本
Syntax: gzip_http_version 1.0|1.1;
Default : gzip_http_version 1.1;
Context:http,server,location
#例:
#location ~ .*\.(txt|xml) {
# gzip on;
# gzip_http_version 1.1;
# gzip_comp_level 2;
# root /opt/app/code/doc;
# }
#拓展Nginx压缩模块
#http_gzip_static_module 预读gzip功能
#例:
#location ~ ^/download {
# gzip_static on;
# tcp_nopush on;
# root /opt/app/code;
# }
#---------------------------------------------------------------------
#浏览器缓存
#-expires配置语法
#添加Cache-Control、Expires头
Syntax: expires [modified] time;
expires epoch | max | off;
Default : expires off;
Context:http,server,location,if in location
#例:
#location ~ .*\.(htm|html)$ {
# expires 24h;
# root /opt/app/code;
# }
#---------------------------------------------------------------------
#跨域访问
Syntax:add_header name value [always];
Default : ——;
Context:http,server,location,if in location
#例:
#location ~ .*\.(htm|html)$ {
# add_header Access-Control-Allow-Origin *;
# add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
# root /opt/app/code;
# }
#---------------------------------------------------------------------
#防盗链 防止网站资源被盗用
#http_refer防盗链配置模块
Syntax:valid_referers none|blocked|server_names|string ...;
Default : ——;
Context:server,location
#例:
# location ~ .*\.(jpg|gif|png)$ {
# 允许没有代理 不允许非http 允许的ip...
# valid_referers none blocked 116.62.103.228 jeson.imoocc.com ~wei\.png;
# if ($invalid_referer) {
# return 403;
# }
# root /opt/app/code/images;
# }