标签: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
原文地址:http://fengwan.blog.51cto.com/508652/1825768