码迷,mamicode.com
首页 > Web开发 > 详细

利用Nginx sub模块对网页内容进行替换

时间:2016-07-12 19:44:58      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:nginx sub

在我们环境下,经常需要运营对网站进行测试,但是偶尔会出现不知道是在测试环境还是正式环境,因为测试环境都是通过Nginx反向代理进行访问.因此本文利用Nginx进行网页内容替换,然后在醒目位置进行提醒,以达到对测试环境的标识作用


在编译nginx的时候添加--with-http_sub_module以加载sub模块

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module

如果全是测试环境的反向代理就只需要在http里头添加,当然也可以针对单个站点

sub_filter <body ‘<div style="border: red 1px solid;width: 100px;text-align: center;line-height: 30px;height: 30px;font-size: 14px;z-index: 999999999;position: fixed;top: 80px;font-weight: bold;background-color: yellow;left: 10px;">测试服务器</div><body‘;
sub_filter_once off;

上面就是将"<body"替换为"<div style="border: red 1px solid;width: 100px;text-align: center;line-height: 30px;height: 30px;font-size: 14px;z-index: 999999999;position: fixed;top: 80px;font-weight: bold;background-color: yellow;left: 10px;">测试服务器</div><body"

格式就是

sub_filter src_string  dst_string;

sub_filter_once off;


然后效果就是

技术分享

每打开一次页面都会有这个提示,就很容易知道是测试服务器了.

本文出自 “枫林晚” 博客,请务必保留此出处http://fengwan.blog.51cto.com/508652/1825768

利用Nginx sub模块对网页内容进行替换

标签:nginx sub

原文地址:http://fengwan.blog.51cto.com/508652/1825768

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!