Archive for the ‘Web Server’ Category

配置独立运行的jsp预编译ant脚本

星期四, 5月 8th, 2008

配置resin开启预编译jsp,在启动时,resin会自动编译jsp,出错信息在 stdout.log中。

[code]
<web-app id=”/lizongbo” document-directory=”webapps/lizongbo”>
<listener>
<listener-class>com.caucho.jsp.JspPrecompileListener</listener-class>
<init>
<extension>jsp</extension>
<extension>jspx</extension>
<extension>xtp</extension>
</init>
</listener>
</web-app>
[/code]

在开发过程,经常将页面传到resin上,才发现页面编译失败,浪费了不少时间,因此需要一个在本地预编译进行检查的操作。

resin 3.1以前的版本提供命令行方式进行jsp预编译。

完整的命令例子如下
%JAVA_HOME%\bin\java.exe -classpath %JAVA_HOME%\lib\tools.jar;D:\Java\resin-3.0.19\lib\aopalliance.jar;D:\Java\resin-3.0.19\lib\ejb-20.jar;D:\Java\resin-3.0.19\lib\ejb-30.jar;D:\Java\resin-3.0.19\lib\j2eedeploy.jar;D:\Java\resin-3.0.19\lib\jca-15.jar;D:\Java\resin-3.0.19\lib\jms-11.jar;D:\Java\resin-3.0.19\lib\jmx-12.jar;D:\Java\resin-3.0.19\lib\jsdk-24.jar;D:\Java\resin-3.0.19\lib\jstl-11.jar;D:\Java\resin-3.0.19\lib\jta-101.jar;D:\Java\resin-3.0.19\lib\portlet-10.jar;D:\Java\resin-3.0.19\lib\quercus.jar;D:\Java\resin-3.0.19\lib\resin-jdk15.jar;D:\Java\resin-3.0.19\lib\resin.jar;D:\Java\resin-3.0.19\lib\resinboot.jar;D:\Java\resin-3.0.19\lib\script-10.jar;D:\Java\resin-3.0.19\lib\webutil.jar;D:\Java\resin-3.0.19\plugins\resin-ant.jar com.caucho.jsp.JspCompiler -app-dir  E:\lizongbo\workspace\webapp E:\lizongbo\workspace\webapp
使用起来很不方便。(注意classpath里特意加了%JAVA_HOME%\lib\tools.jar,否则会报错,
出错信息如下:
Exception in thread “main” com.caucho.java.JavaCompileException: Resin can’t loa
d com.sun.tools.javac.Main.  Usually this means that the JDK tools.jar is missin
g from the classpath, possibly because of using a JRE instead of the JDK.  You c
an either add tools.jar to the classpath or change the compiler to an external o
ne with <java compiler=’javac’/> or jikes.

java.lang.ClassNotFoundException: com.sun.tools.javac.Main
at com.caucho.java.InternalCompiler.compileInt(InternalCompiler.java:77)
at com.caucho.java.AbstractJavaCompiler.run(AbstractJavaCompiler.java:101)
at java.lang.Thread.run(Thread.java:595)
)

resin 3.1.5及以后的版本终于提供了 ant方式的jspc的atsk,但是却有bug。
[code]
<project name=”test” default=”test” basedir=”.”>
<property name=”resin.home” value=”/usr/local/share/resin”/>

<target name=”test”>
<taskdef name=”resin-jspc
classname=”com.caucho.ant.Jspc”>
<classpath>
<fileset dir=”${resin.home}”>
<include name=”plugins/resin-ant.jar”/>
<include name=”lib/*.jar”/>
</fileset>
</classpath>
</taskdef>

<resin-jspc rootDirectory=”/home/ferg/ws/dist/my-webapp”/>
</target>

</project>
[/code]
来源: http://wiki.caucho.com/--escaped_anchor:0fd040dca4b275d0386c280bf39bd048--
在该方式下,会遇到提示说contentType重复定义的bug
出错信息如下:
E:\lizongbo\workspace\webapp\WEB-INF\ant\resin-jspc.xml:38:
com.caucho.jsp.JspLineParseException: /618119/test.jsp:6: contentType ‘text/vnd.wap.wml; charset=UTF-8′ conflicts with previous value of contentType ‘text/html; charset=UTF-8′.  Check the .jsp and any included .jsp files for conflicts.

原因是resin 3.1 对带BOM格式的UTF-8编码的jsp识别有问题。
参考: http://anotherbug.blog.chinajavaworld.com/entry/3683/0/

此时改页面是件痛苦的事情,于是想到使用Tomcatant jspC task

Tomcat 6.0.16的文件目录已经发生了变化,而官方的jspC的文档还没有更新:
http://tomcat.apache.org/tomcat-6.0-doc/jasper-howto.html

以前写过一篇笔记,基本是copy tomcat的官方文档
参考: http://blog.donews.com/lizongbo/archive/2005/06/06/413985.aspx
而现在主要用resin,因此想要一个可以独立进行jsp预编译的ant脚本,
所以手工清理后制作了个独立的jspc,方便随时预编译.

所用到的jar文件为:D:\Java\apache-tomcat-6.0.16\lib和D:\Java\apache-tomcat-6.0.16\bin 目录下所有jar
[code]
D:\Java\jspc\tomcat6lib 的目录

2008-05-08  20:09    <DIR>          .
2008-05-08  20:09    <DIR>          ..
2008-01-28  23:39            10,368 annotations-api.jar
2008-01-28  23:39            17,530 bootstrap.jar
2008-01-28  23:39            49,240 catalina-ant.jar
2008-01-28  23:39           122,869 catalina-ha.jar
2008-01-28  23:39           228,175 catalina-tribes.jar
2008-01-28  23:39         1,128,229 catalina.jar
2008-01-28  23:39             9,341 commons-daemon.jar
2008-01-28  23:39            27,699 el-api.jar
2008-01-28  23:39           102,129 jasper-el.jar
2008-01-28  23:39         1,395,270 jasper-jdt.jar
2008-01-28  23:39           511,240 jasper.jar
2008-01-28  23:39            72,408 jsp-api.jar
2008-01-28  23:39            85,287 servlet-api.jar
2008-01-28  23:39           742,089 tomcat-coyote.jar
2008-01-28  23:39           197,846 tomcat-dbcp.jar
2008-01-28  23:39            18,980 tomcat-juli.jar
16 个文件      4,718,700 字节
2 个目录    895,870,976 可用字节
[/code]

tomcat-jspc.bat的内容为:
(因为jsp文件太多,消耗内存较大,因此通过 ANT_OPTS=-Xmx512m 指定内存)
[code]
set ANT_OPTS=-Xmx512m
ant -f tomcat-jspc.xml -Dwebapp.name=mywebapp
[/code]
tomcat-jspc.properties的内容为:
[code]
webapp.root=E:/lizongbo/workspace
webapp.name = webapp
[/code]

tomcat-jspc.xml的内容如下:

[code]
<project name=”Webapp Precompilation” default=”all” basedir=”.”>
<property file=”${basedir}/tomcat-jspc.properties”/>
<property name=”tomcatlib.home” value=”${basedir}/tomcat6lib”/>
<property name=”webapp.path” value=”${webapp.root}/${webapp.name}”/>
<description> JSPC Tasks</description>
<taskdef resource=”org/apache/catalina/ant/catalina.tasks”>
<classpath>
<fileset file=”${tomcatlib.home}/tomcat-juli.jar”/>
<fileset file=”${tomcatlib.home}/jasper.jar”/>
<fileset file=”${tomcatlib.home}/jasper-el.jar”/>
<fileset file=”${tomcatlib.home}/el-api.jar”/>
<fileset file=”${tomcatlib.home}/jsp-api.jar”/>
<fileset file=”${tomcatlib.home}/servlet-api.jar”/>
<fileset file=”${tomcatlib.home}/catalina-ant.jar”/>
</classpath>
</taskdef>
<taskdef resource=”org/apache/catalina/ant/jmx/jmxaccessor.tasks”>
<classpath>
<fileset file=”${tomcatlib.home}/catalina-ant.jar”/>
</classpath>
</taskdef>
<typedef
name=”jmxEquals”
classname=”org.apache.catalina.ant.jmx.JMXAccessorEqualsCondition”>
<classpath>
<fileset file=”${tomcatlib.home}/catalina-ant.jar”/>
</classpath>
</typedef>
<typedef
name=”jmxCondition”
classname=”org.apache.catalina.ant.jmx.JMXAccessorCondition”>
<classpath>
<fileset file=”${tomcatlib.home}/catalina-ant.jar”/>
</classpath>
</typedef>
<!– 先把WEB-INF/src下的java文件编译成class –>
<target name=”compilejava”>
<echo>jdk path: ${java.home} </echo>
<echo>webapp path: ${webapp.path} </echo>

<mkdir dir=”${webapp.path}/WEB-INF/classes”/>
<mkdir dir=”${webapp.path}/WEB-INF/lib”/>

<javac destdir=”${webapp.path}/WEB-INF/classes”
optimize=”off”
debug=”on” failonerror=”false”
encoding=”utf-8″ nowarn=”true” target=”1.5″
srcdir=”${webapp.path}/WEB-INF/src”
excludes=”**/*.smap”>
<classpath>
<pathelement location=”${webapp.path}/WEB-INF/classes”/>
<fileset dir=”${webapp.path}/WEB-INF/lib”>
<include name=”*.jar”/>
</fileset>
<pathelement location=”${tomcatlib.home}”/>
<fileset dir=”${tomcatlib.home}”>
<include name=”*.jar”/>
</fileset>
</classpath>
<include name=”**” />
<exclude name=”tags/**” />
</javac>

</target>
<!– 再把jsp页面生成java文件 –>
<target name=”jspc”>
<jasper
validateXml=”false”
uriroot=”${webapp.path}”
webXmlFragment=”${webapp.path}/WEB-INF/generated_web.xml”
outputDir=”${webapp.path}/WEB-INF/jspsrc” />

</target>
<!– 再把jsp的java代码编译成class –>
<target name=”compilejspjava”>

<mkdir dir=”${webapp.path}/WEB-INF/work”/>
<mkdir dir=”${webapp.path}/WEB-INF/lib”/>

<javac destdir=”${webapp.path}/WEB-INF/work”
optimize=”off”
debug=”on” failonerror=”true”
encoding=”utf-8″ nowarn=”true” target=”1.5″
srcdir=”${webapp.path}/WEB-INF/jspsrc”
excludes=”**/*.smap”>
<classpath>
<pathelement location=”${webapp.path}/WEB-INF/classes”/>
<fileset dir=”${webapp.path}/WEB-INF/lib”>
<!– need ignore mywebapp/WEB-INF/lib/servlet.jar 在这里忽略掉webapp lib里的低版本的servlet,以免编译失败–>
<exclude name=”servlet.jar”/>
<include name=”*.jar”/>
</fileset>
<pathelement location=”${tomcatlib.home}”/>
<fileset dir=”${tomcatlib.home}”>
<include name=”*.jar”/>
</fileset>
</classpath>
<include name=”**” />
<exclude name=”tags/**” />
</javac>

</target>

<target name=”all” depends=”compilejava,jspc,compilejspjava,cleanup”>
</target>

<target name=”cleanup”>
<delete includeEmptyDirs=”true”>
<fileset dir=”${webapp.path}/WEB-INF/jspsrc”/>
<fileset dir=”${webapp.path}/WEB-INF/work”/>
</delete>
</target>

</project>
[/code]

Tags: ant, eclipse, javac, jspc, Resin, Tomcat

Related posts

在Tomcat 6.0.14中安装配置awstats

星期五, 12月 7th, 2007

Tomcat 6.0.x中配置awstats
需要下载的文件有:

perl : http://downloads.activestate.com/ActivePerl/Windows/5.8/ActivePerl-5.8.8.822-MSWin32-x86-280952.msi
来源: http://www.activestate.com/store/activeperl/download/

http://update.cz88.net/soft/qqwry.rar
http://awstats.sourceforge.net/files/awstats-6.8.tar.gz

geoip插件相关:
http://www.maxmind.com/download/geoip/api/pureperl/Geo-IP-PurePerl-1.18.tar.gz
http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
http://www.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz

安装过程可参考

参考: http://blog.zhangjianfeng.com/article/317
PurePerl.pm的安装可参考:
http://topic.csdn.net/u/20070323/11/903dd121-10d8-42d2-b4eb-a6cb60a22e8a.html

其它配置可参考:
http://www.chedong.com/blog/archives/000410.html

http://blogger.org.cn/blog/more.asp?name=chenjiejacky&id=20464

安装perl之后,确认环境变量里PATH有perl的bin目录
Path=E:\oracle\product\10.2.0\client_1\bin;D:\Perl\bin;
D:\Java\jdk1.6.0_03\bin;E:\oracle\product\10.2.0\db_1\bin;
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;
C:\Program Files\Microsoft SQL Server\80\Tools\BINN

1.为了控制查看awstats的权限,我在
E:\apache-tomcat-6.0.14\conf\tomcat-users.xml的内容配置为:

<?xml version=’1.0′ encoding=’utf-8′?>
<tomcat-users>
<role rolename=”awstats”/>
<user username=”awstats” password=”awstats” roles=”awstats”/>
</tomcat-users>

2.由于权限限制

E:\apache-tomcat-6.0.14\webapps\awstats\META-INF\context.xml,内容为:

<!– tomcat 6.0 need privileged is true for CGIServlet –>
<Context reloadable=”true” privileged=”true” >

</Context>

否则启动的时候会出下面的错误信息:

[ERROR]main-org.apache.catalina.startup.HostConfig-Error deploying web application directory awstats
java.lang.SecurityException: Servlet of class org.apache.catalina.servlets.CGIServlet is privileged and cannot be loaded by this web application
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1134)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
3.配置web.xml,增加权限控制
web.xml的内容为:

<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd” version=”2.4″>
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>clientInputTimeout</param-name>
<param-value>100</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi-bin</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
<!– Define reference to the user database for looking up roles –>
<resource-env-ref>
<description>
Link to the UserDatabase instance from which we request lists of
defined role names. Typically, this will be connected to the global
user database with a ResourceLink element in server.xml or the context
configuration file for the Manager web application.
</description>
<resource-env-ref-name>users</resource-env-ref-name>
<resource-env-ref-type>org.apache.catalina.UserDatabase</resource-env-ref-type>
</resource-env-ref>
<!– Define a Security Constraint on this Application –>
<security-constraint>
<web-resource-collection>
<web-resource-name>awstats status</web-resource-name>
<url-pattern>/cgi-bin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>awstats</role-name>
</auth-constraint>
</security-constraint>
<!– Define the Login Configuration for this Application –>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Awstats status,username: awstats,password: awstats</realm-name>
</login-config>
<!– Security roles referenced by this web application –>
<security-role>
<description>
The role that is required to log in to the Manager Application
</description>
<role-name>awstats</role-name>
</security-role>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
</web-app>

4.调整文件夹目录

E:\APACHE~1.14\webapps\awstats 的目录

007-12-07 18:14 <DIR> .
007-12-07 18:14 <DIR> ..
007-12-07 08:48 <DIR> classes
007-12-07 08:48 <DIR> css
007-12-07 08:48 <DIR> docs
007-12-07 08:48 <DIR> icon
007-12-07 08:49 211 index.jsp
007-12-07 08:48 <DIR> js
007-12-07 08:56 <DIR> logs
007-12-07 08:48 <DIR> META-INF
007-11-24 22:05 6,721 README.TXT
007-12-07 08:47 <DIR> WEB-INF

E:\APACHE~1.14\webapps\awstats\WEB-INF 的目录

2007-12-07 08:47 <DIR> .
2007-12-07 08:47 <DIR> ..
2007-12-07 08:56 <DIR> cgi-bin
2007-12-07 08:47 <DIR> tools
2007-12-07 08:42 2,389 web.xml

E:\APACHE~1.14\webapps\awstats\WEB-INF\cgi-bin 的目录

007-12-07 08:56 <DIR> .
007-12-07 08:56 <DIR> ..
006-02-09 06:26 5,407 awredir.pl
007-12-07 08:56 2,343 awstats.localhost.conf
007-12-07 08:55 2,340 awstats.localhost.conf.bak
007-11-24 03:18 60,544 awstats.model.conf
007-11-24 03:18 556,625 awstats.pl
007-12-07 08:56 13,569 awstats122007.localhost.txt
006-07-27 09:37 1,847 awstatsext.conf
007-12-07 08:56 678 dnscachelastupdate.localhost.hash
007-12-03 12:18 1,079,842 GeoIP.dat
007-09-13 04:08 2,020,543 GeoIPASNum.dat
007-12-03 16:25 25,914,398 GeoLiteCity.dat
007-12-07 08:48 <DIR> lang
007-12-07 08:48 <DIR> lib
007-03-15 14:35 184 perl插件安装说明.txt
007-12-07 08:54 <DIR> plugins
007-12-05 17:58 6,812,739 QQWry.Dat

E:\APACHE~1.14\webapps\awstats\WEB-INF\cgi-bin\plugins 的目录

2007-12-07 08:54 <DIR> .
2007-12-07 08:54 <DIR> ..
2006-02-09 06:26 3,682 clusterinfo.pm
2006-02-09 06:26 2,960 decodeutfkeys.pm
2007-12-07 08:48 <DIR> example
2007-12-07 08:54 <DIR> geo
2006-05-06 11:51 7,203 geoip.pm
2006-02-09 06:26 3,736 geoipfree.pm
2006-09-04 15:04 112,953 geoip_city_maxmind.pm
2006-05-06 11:54 16,885 geoip_isp_maxmind.pm
2006-05-06 11:54 16,919 geoip_org_maxmind.pm
2006-05-06 11:54 22,283 geoip_region_maxmind.pm
2004-01-01 05:41 5,074 graphapplet.pm
2006-02-09 06:26 5,206 hashfiles.pm
2005-02-19 21:50 7,169 hostinfo.pm
2006-02-09 06:26 2,439 ipv6.pm
2005-04-11 05:08 2,501 qqhostinfo.pm
2005-03-28 11:29 7,603 qqwry.pl
2006-02-09 06:26 4,689 rawlog.pm
2006-02-09 06:26 1,890 timehires.pm
2006-02-09 06:26 2,954 timezone.pm
2006-07-30 03:20 8,212 tooltips.pm
2006-02-09 06:26 4,799 urlalias.pm
2006-02-09 06:26 3,616 userinfo.pm

我的awstats.localhost.conf配置如下:

Include=”common.conf”
PageCode=”GB2312″ # UTF-8
LogFile=”E:/apache-tomcat-6.0.14/logs/access.log
SiteDomain=”618119.com
LoadPlugin=”decodeutfkeys”
LoadPlugin=”hashfiles”
LoadPlugin=”geoip”
LoadPlugin=”tooltips”
LoadPlugin=”qqhostinfo”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD GeoLiteCity.dat”
LoadPlugin=”geoip_org_maxmind GEOIP_STANDARD GeoIPASNum.dat”
LogFormat=1
HostAliases=”localhost 618119.com www.618119.com
DirIcons=”/awstats/icon”
DNSLookup=1
DirData=”.”
DirCgi=”/cgi-bin”
AllowToUpdateStatsFromBrowser=1

Include=”awstatsext.conf”

一个非常有用的参考地址: http://www.antezeta.com/--escaped_anchor:991c60c35b6fb9b719237cdcc0a3ec45--.html

扩展设置:
# form http://www.antezeta.com/--escaped_anchor:991c60c35b6fb9b719237cdcc0a3ec45--.html

ExtraSectionName1=”Google Searches - Top 50″
ExtraSectionCodeFilter1=”200 304″
ExtraSectionCondition1=”REFERER,(.*www\.google.*)”
ExtraSectionFirstColumnTitle1=”Search”
ExtraSectionFirstColumnValues1=”REFERER,p=([^&]+)||REFERER,q=([^&]+)||REFERER,as_p=([^&]+)||REFERER,as_q=([^&]+)”
ExtraSectionFirstColumnFormat1=”<a href=’http://www.google.cn/search?q=%s’ title=’Click to execute search’>%s</a>”
ExtraSectionStatTypes1=PHBL
ExtraSectionAddAverageRow1=0
ExtraSectionAddSumRow1=1
MaxNbOfExtra1=50
MinHitExtra1=1

ExtraSectionName2=”Google crawls - Top 50″
ExtraSectionCodeFilter2=”200 304″
ExtraSectionCondition2=”UA,(.*Googlebot.*)”
ExtraSectionFirstColumnValues2=”URL,(.*)”
ExtraSectionFirstColumnFormat2=”<a href=’http://618119.com%s’ title=’Item Crawled’>%s</a>”
ExtraSectionStatTypes2=PHBL
ExtraSectionAddAverageRow2=0
ExtraSectionAddSumRow2=1
MaxNbOfExtra2=50
MinHitExtra2=1

ExtraSectionName3=”sitemap.xml.gz downloads by Useragent”
ExtraSectionCodeFilter3=”200 304″
ExtraSectionCondition3=”URL,(^\/sitemap\.xml\.gz)”
ExtraSectionFirstColumnTitle3=”UA”
ExtraSectionFirstColumnValues3=”UA,(.*)”
ExtraSectionStatTypes3=HBL
ExtraSectionAddAverageRow3=0
ExtraSectionAddSumRow3=1
MaxNbOfExtra3=10
MinHitExtra3=1

ExtraSectionName4=”Referring Sites by domain - Top 25″
ExtraSectionCodeFilter4=”200 304″
# Filter on ANY REFERER except “mysite”. Change mysite to your domain name.
ExtraSectionCondition4=”REFERER,^(?!http:\/\/www\.618119\.com)”
ExtraSectionFirstColumnTitle4=”Site”
ExtraSectionFirstColumnValues4=”REFERER,^[hH][tT][tT][pP]:\/\/([^\/]+)\/”
ExtraSectionFirstColumnFormat4=”<a href=’http://%s/’ rel=’nofollow’ title=’http://%s/ [new window]‘>%s</a>”
ExtraSectionStatTypes4=PHL
ExtraSectionAddAverageRow4=1
ExtraSectionAddSumRow4=1
MaxNbOfExtra4=25
MinHitExtra4=1

ExtraSectionName5=”Top 30 RSS Readers/Spiders”
ExtraSectionCodeFilter5=”200 304″
ExtraSectionCondition5=”URL,\.xml|\.rdf|\.rss|\/feed”
ExtraSectionFirstColumnTitle5=”RSS Reader/Spider”
ExtraSectionFirstColumnValues5=”UA,(.*)”
ExtraSectionStatTypes5=HBL
ExtraSectionAddAverageRow5=1
ExtraSectionAddSumRow5=1
MaxNbOfExtra5=30
MinHitExtra5=1

ExtraSectionName6=”Downloads (diff,doc,pdf,rtf,sh,tgz,zip) - Top 10″
ExtraSectionCodeFilter6=”200 304″
ExtraSectionCondition6=”URL,(.*((\.diff)|(\.doc)|(\.pdf)|(\.rtf)|(\.sh)|(\.tgz)|(\.zip)))”
ExtraSectionFirstColumnTitle6=”Download”
ExtraSectionFirstColumnValues6=”URL,(.*)”
ExtraSectionFirstColumnFormat6=”%s”
ExtraSectionStatTypes6=HBL
ExtraSectionAddAverageRow6=0
ExtraSectionAddSumRow6=1
MaxNbOfExtra6=10
MinHitExtra6=1

Tags: 618119.com, Apache, Apache Tomcat, awstats, perl

Related posts

给wordpress加上记录Combined格式日志的功能

星期四, 12月 6th, 2007

由于我是合租的web主机,因此开通的ftp里没权限看到站点的access.log,

由于wordpress是通过.htaccess中配置的urlrewrite将http请求重定向到index.php 这个入口,

因此只要在index.php里加上记录日志的操作,基本上大部分请求都可以记录下来,

查了下资料,没看见现成的代码,于是对照着 Combined各式的日志,

自己写了一段代码来实现这个功能.

代码如下:

[code]

<?php
/* Short and sweet */
define(’WP_USE_THEMES’, true);
/**
为我的wordpress增加记录web日志的功能
author: lizongbo
site: http://618119.com
*/

$webaccesslog=”webaccess”.gmdate(”Y-m-d”).”.log”;
$accesslog=$_SERVER['REMOTE_ADDR'].” - - “.gmdate(”[d/M/Y:H:i:s +0800] “);
$accesslog=$accesslog.”\”".$_SERVER["REQUEST_METHOD"].” “.$_SERVER["REQUEST_URI"].” “;
$accesslog=$accesslog.$_SERVER["SERVER_PROTOCOL"].”\”";
$accesslog=$accesslog.” 200 2007 \”";
if(!empty($_SERVER["HTTP_REFERER"])){
$accesslog=$accesslog.$_SERVER["HTTP_REFERER"];
}else{
$accesslog=$accesslog.”-”;
}
$accesslog=$accesslog.”\” \”".$_SERVER["HTTP_USER_AGENT"].”\”".”\r\n”;
$webaccess=fopen($webaccesslog,”a”);
fwrite($webaccess,$accesslog);
/*下面的写法 io 操作太多,被废弃了
fwrite($webaccess,$_SERVER['REMOTE_ADDR']);
fwrite($webaccess,” - - “);
fwrite($webaccess,gmdate (”[d/M/Y:H:i:s +0800] “));//不知道怎么加时区,于是写死了
fwrite($webaccess,”\”");
fwrite($webaccess,$_SERVER["REQUEST_METHOD"]);
fwrite($webaccess,” “);
fwrite($webaccess,$_SERVER["REQUEST_URI"]);
fwrite($webaccess,” “);
fwrite($webaccess,$_SERVER["SERVER_PROTOCOL"]);
fwrite($webaccess,”\”");
fwrite($webaccess,” 200 2007 \”");//强行写死了状态码和内容长度
if(!empty($_SERVER["HTTP_REFERER"])){
fwrite($webaccess,$_SERVER["HTTP_REFERER"]);
}else{
fwrite($webaccess,”-”);
}
fwrite($webaccess,”\” \”");
fwrite($webaccess,$_SERVER["HTTP_USER_AGENT"]);
fwrite($webaccess,”\”");
fwrite($webaccess,”\r\n”);
*/

fclose($webaccess);
require(’./wp-blog-header.php’);
?>

[/code]

这样,记录下来的日志就可以通过ftp下载到本地,然后再用 awstats 进行分析了.

Tags: 618119.com, Apache, log, php, Wordpress

Related posts