nginx拦截HTML页面并修改页面内容(sub_filter简单用法)


可用于对系统进行标记,便于人们直观的区分测试环境\正式环境等

server {

  listen  443 ssl;
  server_name www.baidu.com;

  #ssl on;
  ssl_certificate cert/cert.pem;
  ssl_certificate_key cert/cert.key;
  ssl_session_timeout 5m;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
  ssl_prefer_server_ciphers on;

  set $injected '<div style="position: absolute; z-index:9999; color:red; font-size:10px">测试环境</div>';
  sub_filter '<body>' '<body>${injected}';//重点在这  匹配<body>标签替换为<body><div>测试环境<div>这样

  index index.html index.htm index.jsp;
  root /data/sudeng-web/;

  #error_page 404 /404.html;
  #error_page 502 /502.html;

  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }

  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }

  location ~ /\.ht {
    deny all;
  }

}

 

在系统左上角页面都可以标签,项目侵入性也较小

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM