1. 程式人生 > >通過Nginx使全站頁面變灰

通過Nginx使全站頁面變灰

      摘要:某大神的部落格說“在Nginx負載均衡伺服器上,利用sub_filter指令在輸出的HTML中增加一行:
<style type="text/css">html {filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); }</style>

就可以實現在IE及IE核心瀏覽器下,所有網站變灰色。” 特此試驗

主要步驟:

  1、重新編譯nginx,增加http_sub_module模組。

  2、在nginx.conf配置檔案的http {...}大括號內增加以下兩行:

sub_filter  '</head>'  '<style type="text/css">html {filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); }</style></head>';
sub_filter_once on;

正文

一、重新編譯nginx,新增新模組

 1.1 首先,檢視之前編譯的一些引數

  # /usr/local/nginx/sbin/nginx -V

 1.2 進入nginx原始碼包

  # cd /usr/src/nginx-1.10.2

 1.3 重新預配置,將要編譯的引數重新新增到後面(包括之前已經編譯過的模組)

       

 1.4編譯

  #make 

  (*注:這裡只能make 千萬別make install,否則就覆蓋安裝了)

 1.5 make完成後,在原始碼目錄下會有一個objs目錄,objs目錄下就多了個nginx,這個就是新版本的程式了。

       

  將objs目錄下的nginx替換之前已經安裝過的nginx程式。

       先備份舊的nginx程式,然後將新的nginx程式覆蓋過來

       

  如果提示“cp:cannot create regular file `/usr/local/nginx/sbin/nginx': Text file busy”,建議使用如下語句cp    #cp -rfp objs/nginx /usr/local/nginx/sbin/nginx

 1.6 檢視配置資訊

       

 1.7  測試新的nginx程式是否正確

  # /usr/local/nginx/nginx -t

   nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok

   nginx: configuration file /usr/local/nginx/nginx.conf test is successful

  重啟服務

   # /usr/local/nginx/nginx -s reload

       

二、修改配置檔案

        在nginx.conf配置檔案的http {...}大括號內增加以下兩行:

  sub_filter  '</head>'  '<style sub_filter  '</head>'  '<style type="text/css">html {filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); }</style></head>';

  sub_filter_once on;                                                                                                                                                                                                          

   儲存後,重新載入配置檔案:

  /usr/local/webserver/nginx/sbin/nginx –t

  /usr/local/webserver/nginx/sbin/nginx -s reload

 用ie瀏覽器測試

   

並沒有變灰