h0945466 发表于 2018-11-28 12:34:52

Apache下设置整站变灰方法

  本文转载自http://www.sapub.net/Apache,感谢作者分享!
  Web服务器下设置变灰的方法比较简单,总结如下:
  1、安装mod_ext_filter模块(此模块用来在所有的输出页面插入你想要的内容,比如css,广告头之类)
  这里假设apache已经在运行,因此不需要重新编译apache,只新增mod_ext_filer模块。
  cd httpd-2.2.15/modules/filters
  apxs -cia mod_ext_filter.c
  2、修改httpd.conf
  1)定义过滤器(filter)的名字(这里为graypage)和配置filter要调用程序的名字(graypage.pl)
  ExtFilterDefine graypage mode=output intype=text/html cmd="/usr/local/bin/graypage.pl"
  2)Directory添加SetOutputFilter graypage,添加后完整的配置类似下面这样:
  SetOutputFilter表示对所有输出使用过滤器
  Options Indexes FollowSymLinks
  AllowOverride All
  SetOutputFilter graypage
  Order allow,deny
  Allow from all
  /var/www/htdocs为DocumentRoot的路径。
  3.创建/usr/local/bin/graypage.pl,内容如下:
  #!/usr/bin/perl
  my @lines = ;
  open GRAYLINE, "/var/www/htdocs/gray-css.txt" or die "cant't find the css file.";
  my @graylines = ;
  print @lines,@graylines;
  注意加上可执行权限:chmod +x /usr/local/bin/graypage.pl
  注:/var/www/htdocs/假设为documnentroot路径。
  4.创建/var/www/htdocs/gray-css.txt,内容如下:
  html {filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); }
  这段代码是使IE类浏览器变灰的CSS。(Firefox下无效)
  5.重启Apache
  apachectl graceful
  提示:
  很多站点是租用的服务器,可能没有权限修改web服务器,那么可以简单的在css文件(如果有全局css最好,比如WordPress的style.css)最后加入
  html{filter: gray;}
  除非是全局css,否则只会让某个页面变灰,而不能实现直接修改web服务器那样让所有页面都变灰。

页: [1]
查看完整版本: Apache下设置整站变灰方法