nginx向响应内容中追加内容(ngx_http_addition_module模块)
2014-03-23 00:00
411 查看
ngx_http_addition_module在响应之前或者之后追加文本内容,比如想在站点底部追加一个js或者css,可以使用这个模块来实现,这个模块和淘宝开发的nginx footer模块有点类似,但是还是有不同. 这个模块需要依赖子请求,nginx footer依赖nginx写死的配置.
1. 安装nginx
如何安装nginx第三方模块
2. 指令(Directives) 语法: add_before_body uri; 默认值: — 配置段: http, server, location 发起一个子请求,请求给定的uri,并且将内容追加到主题响应的内容之前。 语法: add_after_body uri; 默认值: — 配置段: http, server, location 发起一个子请求,请求给定的uri,并且将内容追加到主题响应的内容之后。 syntax: addition_types mime-type ...; default: addition_types text/html; context: http, server, location 这个指令在0.7.9开始支持,指定需要被追加内容的MIME类型,默认为“text/html”,如果制定为*,那么所有的
3. nginx配置addition
3.1 配置nginx.conf
3.2 测试 以下三个文件,对应请求的主体文件和add_before_body、add_after_body对应的内容
4. 结束语 addition模块与上节上节nginx sub替换响应内容模块应用场景有点相同,具体怎么使用,大家结合实际情况来使用.欢迎大家继续访问运维生存时间. 转载请注明来自运维生存时间:http://www.ttlsa.com/html/3294.html
1. 安装nginx
# wget http://nginx.org/download/nginx-1.4.2.tar.gz # tar -xzvf nginx-1.4.2.tar.gz # cd nginx-1.4.2 # --prefix=/usr/local/nginx-1.4.2 --with-http_stub_status_module --with-http_addition_module # make # make install如果你已经安装了nginx,只想增加模块,请参考ttlsa以前的文章
如何安装nginx第三方模块
2. 指令(Directives) 语法: add_before_body uri; 默认值: — 配置段: http, server, location 发起一个子请求,请求给定的uri,并且将内容追加到主题响应的内容之前。 语法: add_after_body uri; 默认值: — 配置段: http, server, location 发起一个子请求,请求给定的uri,并且将内容追加到主题响应的内容之后。 syntax: addition_types mime-type ...; default: addition_types text/html; context: http, server, location 这个指令在0.7.9开始支持,指定需要被追加内容的MIME类型,默认为“text/html”,如果制定为*,那么所有的
3. nginx配置addition
3.1 配置nginx.conf
server { listen 80; server_name www.ttlsa.com; root /data/site/www.ttlsa.com; location / { add_before_body /2013/10/header.html; add_after_body /2013/10/footer.html; } }
3.2 测试 以下三个文件,对应请求的主体文件和add_before_body、add_after_body对应的内容
# cat /data/site/test.ttlsa.com/2013/10/20131001_add.html <html> <head> <title>I am title</title> </head> <body> ngx_http_addition_module </body> </html> # cat /data/site/test.ttlsa.com/2013/10/header.html I am header! # cat /data/site/test.ttlsa.com/2013/10/footer.html footer - ttlsa访问结果如下,可以看到20131001_add.html的顶部和底部分别嵌入了子请求header.html和footer的内容。
# curl test.ttlsa.com/2013/10/20131001_add.html I am header! <html> <head> <title>I am title</title> </head> <body> ngx_http_addition_module </body> </html> footer - ttlsa
4. 结束语 addition模块与上节上节nginx sub替换响应内容模块应用场景有点相同,具体怎么使用,大家结合实际情况来使用.欢迎大家继续访问运维生存时间. 转载请注明来自运维生存时间:http://www.ttlsa.com/html/3294.html
相关文章推荐
- nginx向响应内容中追加内容(ngx_http_addition_module模块)
- nginx中http_addition_module模块(向响应内容中追加内容)
- nginx 替换网站响应内容(ngx_http_sub_module)
- nginx替换网站响应内容(ngx_http_sub_module)
- nginx替换网站响应内容(ngx_http_sub_module)
- nginx快速绘制圆形图(ngx_http_circle_gif_module模块)
- nginx记录分析网站响应慢的请求(ngx_http_log_request_speed)
- nginx限制连接数ngx_http_limit_conn_module模块
- nginx记录分析网站响应慢的请求(ngx_http_log_request_speed)
- Nginx 的ngx_http_core_module模块
- nginx统计响应的http状态码信息(ngx-http-status-code-counter)
- nginx记录分析网站响应慢的请求(ngx_http_log_request_speed)
- nginx中http_sub_module模块(替换网站响应内容)
- nginx记录分析网站响应慢的请求(ngx_http_log_request_speed)
- nginx限制连接数ngx_http_limit_conn_module模块
- nginx记录分析网站响应慢的请求(ngx_http_log_request_speed)
- nginx统计响应的http状态码信息(ngx-http-status-code-counter)
- nginx限制连接数ngx_http_limit_conn_module模块
- 详细解释:nginx中ngx_http_headers_module模块配置及各个参数含义
- nginx限制连接数ngx_http_limit_conn_module模块