【随笔】nginx add_header指令的使用
nginx配置文件通过使用add_header指令来设置response header。
具体方法如下:
add_header key value
add_header Cache-Control no-store
add_header Content-Encoding gzip
用以改变Content-Type时比较特殊,可以在它设置了类型的同时还会指定charset,不过Content-Type和charset之间有分号,所以我们需要这样来添加。
add_header Content-Type 'text/html; charset=utf-8';
这样就可以给responent header的Content-Type添加指定的属性了。
例如:
nginx设置:
http {
include mime.types;
default_type application/octet-stream ;
sendfile on;
keepalive_timeout ;
server {
listen ;
server_name localhost;
index index.html index.htm;
root /usr/local/openresty/nginx/work;
location ~* .(js)$ {
add_header Content-Type 'text/javascript;charset=utf-8';
}
location /dir {
default_type application/javascript;
content_by_lua_file /usr/local/openresty/nginx/work/resources/lua/index.lua;
}
}
}
其中匹配所有.js文件,给其responent header的Content-Type值赋值为"text/javascript;charset=utf-8"。
【随笔】nginx add_header指令的使用的更多相关文章
- Nginx 配置指令location 匹配符优先级和安全问题【转】
Nginx配置指令location匹配符优先级和安全问题 使用nginx 很久了,它的性能高,稳定性表现也很好,得到了很多人的认可.特别是它的配置,有点像写程序一样,每行命令结尾一个";&q ...
- nginx log_format指令记录自定义响应头
我们用的nginx有做过一些定制开发,为了调试方便,加了一些自定义的response header,那么如何把这个自定义头记录到日志中以便于观察呢? nginx log_format指令支持这种扩展, ...
- Nginx try_files 指令
Nginx try_files 指令 按顺序检查文件是否存在,返回第一个找到的文件.结尾的斜线表示为文件夹 -$uri/.如果所有的文件都找不到,会进行一个内部重定向到最后一个参数. 务必确认只有最后 ...
- nginx rewrite 指令
ginx通过ngx_http_rewrite_module模块支持url重写.支持if条件判断,但不支持else. 该模块需要PCRE支持,应在编译nginx时指定PCRE源码目录, nginx安装方 ...
- Nginx Location指令配置及常用全局变量
./configure的含义 在实践安装nginx的时候,不知道./configure是什么意思,这里特地记录一下. 在linux中./代表当前目录,属于相对路径../代表上一级目录,属于相对路径/代 ...
- nginx proxy_pass 指令
nginx proxy_pass 指令 文档 Nginx 官方文档 https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pa ...
- nginx.conf指令注释
nginx.conf指令注释 ######Nginx配置文件nginx.conf中文详解##### #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于C ...
- nginx rewrite 指令last break区别最详细的解释
转自:http://blog.sina.com.cn/s/blog_4f9fc6e10102ux0w.html http://blog.cafeneko.info/2010/10/nginx_rewr ...
- Nginx 配置指令的执行顺序(十一)
紧跟在 post-access 阶段之后的是 try-files 阶段.这个阶段专门用于实现标准配置指令 try_files 的功能,并不支持 Nginx 模块注册处理程序.由于 try_files ...
随机推荐
- [leetcode]58. Length of Last Word最后一个词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- [leetcode]39. Combination Sum组合之和
Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), fin ...
- git创建新的分支
1.本地创建一个新的分支 git branch develop 2.切换到新创建的分支 git checkout develop 3.将新的分支发布到gitlab上 git push origin d ...
- css3回顾 checkbox
<div class="checkBox"> <input type="checkbox" id="check1"> ...
- CentOS7 Failed to start LSB: Bring up/down networking.解决方法
https://www.cnblogs.com/bonjov1/p/4323836.html CentOS7 Failed to start LSB: Bring up/down networking ...
- 20172325 2018-2019-2 《Java程序设计》第九周学习总结
20172325 2018-2019-2 <Java程序设计>第九周学习总结 教材学习内容总结 图的定义 图是由顶点集(VertexSet)和边集(EdgeSet)组成,针对图G,顶点集和 ...
- centos7.2 下 nginx 开机启动
1.在系统服务目录里创建nginx.service文件 1 vi /lib/systemd/system/nginx.service 内容如下 1 2 3 4 5 6 7 8 9 10 11 12 1 ...
- 《机器学习实战(基于scikit-learn和TensorFlow)》第二章内容的学习心得
请支持正版图书, 购买链接 下方内容里面很多链接需要我们***,请大家自备梯子,实在不会再请留言,节约彼此时间. 源码在底部,请自行获取,谢谢! 当开始着手进行一个端到端的机器学习项目,大致需要以下几 ...
- CentOS 配置SOCKS5代理服务
SOCKS5 是一个代理协议,它在使用TCP/IP协议通讯的前端机器和服务器机器之间扮演一个中介角色,使得内部网中的前端机器变得能够访问Internet网中的服务器,或者使通讯更加安全 通过yum安装 ...
- Dispatch Queue 之 Invoke 当前队列