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