一、安装NGINX和替换模块
1、下载
wget -c http://www.nginx.org/download/nginx-1.0.8.tar.gz
svn checkout http://substitutions4nginx.googlecode.com/svn/trunk/ substitutions4nginx-read-only
本站下载地址:soft.ileiming.com/substitutions4nginx-read-only.tar.gz
2、解压
tar zxf nginx-1.0.8.tar.gz
3、编译
./configure –prefix=/usr/local/nginx –user=www –group=www –with-http_stub_status_module –with-http_ssl_module –with-pcre –with-http_realip_module –add-module=path/substitutions4nginx-read-only
此处的path是存放substitutions4nginx-read-only的路径
二、配置
新建一个站点的配置文件,如下内容
server
{
listen 80;
server_name www.test.com;
location / {
proxy_pass http://www.dianxin.cn;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
subs_filter 11001072 123456789;
index index.html index.htm;
}
}
保存退出重启nginx
这里的subs_filter 11001072是网站上需要替换的代码, 123456789是你想替换上去的内容
转载请注明:IT运维空间 » linux » NGINX反向代理并替换内容
发表评论