麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 網(wǎng)站 > Nginx > 正文

nginx使用replace-filter-nginx-module實現(xiàn)內(nèi)容替換的示例

2024-08-30 12:29:30
字體:
來源:轉載
供稿:網(wǎng)友

有時候我們想對響應(例如PHP接口)返回的內(nèi)容做些字符串,雖然可以使用各語言代碼相關方法(例如PHP的str_replace)進行替換,但是在nginx層面替換是更方便的,無需修改代碼。

約定:本文源代碼目錄統(tǒng)一放在:/root/soft/src 里。

安裝

安裝此模塊需要先安裝 sregex 運行庫:

$ git clone https://github.com/agentzh/sregex$ cd sregex$ make$ make install

然后安裝 replace-filter-nginx-module 模塊:

$ cd /root/soft/src$ git clone https://github.com/agentzh/replace-filter-nginx-module$ wget http://nginx.org/download/nginx-1.12.2.tar.gz$ tar zxvf nginx-1.12.2.tar.gz

這里采用靜態(tài)編譯的方式安裝模塊,需要重新編譯 nginx 。獲取 nginx 上一次編譯參數(shù):

$ nginx -Vnginx version: nginx/1.12.2built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013TLS SNI support enabledconfigure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-ld-opt=-ljemalloc --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module 

這里添加 replace-filter-nginx-module 模塊:

--add-module=/root/soft/src/replace-filter-nginx-module

最終編譯命令:

cd nginx-1.12.2$ ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-ld-opt=-ljemalloc --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --add-module=/root/soft/src/replace-filter-nginx-module $ make

由于這里是升級nginx,所以千萬不要make install,不然就真的覆蓋了。 接下來手動替換二進制文件:

$ cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak$ cp -rfp ./objs/nginx /usr/local/nginx/sbin/

測試是否可行:

$ nginx -vnginx version: nginx/1.12.2

配置是否正常:

$ /usr/local/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

配置

這里測試的是:把接口返回的 img.test.com 換成 media.test.com。

修改: /usr/local/nginx/conf/vhost/test.com.conf

location ~ [^/]/.php(/|$){  # comment try_files $uri =404; to enable pathinfo  try_files $uri =404;  fastcgi_pass 127.0.0.1:9000;  fastcgi_index index.php;  include fastcgi.conf;}

為:

location ~ [^/]/.php(/|$){  replace_filter 'img.test.com' 'media.test.com' g;  replace_filter_types application/json;    # comment try_files $uri =404; to enable pathinfo  try_files $uri =404;  fastcgi_pass 127.0.0.1:9000;  fastcgi_index index.php;  include fastcgi.conf;

注意需要添加replace_filter_types 。

保存后檢查配置是否ok:

$ /usr/local/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

然后熱重啟:

# 升級完成第一次需要重啟$ service nginx restart  # 熱重啟$ /usr/local/nginx/sbin/nginx -s reload

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關教程知識閱讀請移步到服務器教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 91色一区二区三区 | 亚洲一区二区三区91 | 99re66热这里只有精品8 | 91网址在线播放 | 91成人影院| 手机av在线电影 | 原来神马影院手机版免费 | 91久久国产露脸精品国产护士 | 插插操| 国产精品1区2区在线观看 | 欧美一级免费高清 | 91在线视频播放 | 日本aaaa片毛片免费观看视频 | 久草在线手机观看 | 202z中文字幕第一页 | 成人羞羞网站入口 | 国产精品av久久久久久网址 | xxxeexxx性国产 | 国产中出在线观看 | 国产成人高清在线观看 | 日韩一级免费毛片 | wwwxxx国产| 99精品国产一区二区三区 | 国产精品成人一区二区三区吃奶 | 草草在线视频 | 日本在线观看视频网站 | 日韩毛片一区二区三区 | 极品美女一级毛片 | 欧美在线成人影院 | 久久精品99国产国产精 | 手机在线看片国产 | 久久99精品久久久久久236 | 国产91在线高潮白浆在线观看 | 99精品国产一区二区三区 | 中国女人内谢8xxxxxx在 | 久久综合综合久久 | 亚洲欧美一区二区三区在线观看 | www.17c亚洲蜜桃 | 欧美精品亚洲人成在线观看 | 一级黄色毛片免费 | 成人福利网 |