澳门新葡亰平台游戏网站Apache-2.4+Tomcat-7+SSL +VirtualHost+自签发证书安装测试

1.作者:moonsbird
题目:Windows下Apache+Tomcat+MySQL+jsp+php的服务器整合配置经验总结
时间:2004.8.19 最初发表于西南交通大学锦城驿站
2.本文是作者学习几年来学习jsp/配置服务器环境的经验总结。可以转载,但请注明出处.
开始学习jsp很久了,网上有许多关于jsp整合的例子,但存在着许多问题。
对于Apache+Tomcat+MySQL+jsp+php的整合,针对不同的Tomcat和apache的版本,稍微有些区别。
即使你E文很好,去看Tomcat和Apache的手册,也不一定能完全整合成功。暑假在家,网速不像
在交大那样—老黄牛拉破车样的慢,所以基于此作者查阅大量网上资料,汲其精华,写这篇文
章希望能为初学者提供方便,也可以作为高手的参考手册。
jsp是优秀的,它基于Java技术,利用JavaBean/Servlet制作动态网站,Java强大的面向对
象编程使Jsp相对于php和asp有着得天独厚的优势。但学习jsp相对于php和asp来说是有难度的。
我想原因之一就是jsp服务器环境的配置要棘手一些。对于动态网页制作,在交大asp曾很长时
间占据上风,不太多的“高手”(也许很多人认为使用jsp的是高手吧)使用jsp,交大比较成功的
jsp网站如世纪星网(Tomcat)、网络教育学院网站(Resin)、交大招生就业网(Tomcat),服务器是
Linux
9,运行相对来说比较稳定可靠。Linux下的Apache和Tomcat整合我曾经发过一篇文章,需
要的大家在锦城搜搜。linux和windows下整合思想是相同的,利用apache来解析*.html/*.htm
静态网页,当遇到*.jsp和servlet时,通过一个apache中的module把jsp页面抛给Tomcat下,在apache的配置文件中下入以下几行,使之
支持php. ScriptAlias /php/ “d:/server/php/” AddType application/x- .php3
AddType application/x- .php AddType application/x- .phtml Action
application/x- “/php/php.exe”
在d:serverwww下建立网页:index.php,内容为: html
headtitlephp测试/title/head ?php phpinfo(); ? /html
用文本编辑器编辑好为存为index.php,重新启动apache,在IE中输入,如果出现php的
环境变量,说明php,安装成功,如果不能解析?php phpinfo();
?中的部分,则说明没有成功安装。

Apache-2.4+Tomcat-7+SSL +VirtualHost+自签发证书安装测试

一、安装依懒软件包

1、安装apr软件包
# wget -c

#tar -jxvf apr-1.5.2.tar.bz2
#cd apr-1.5.2
# ./configure –prefix=/usr/
#make
# make install

2、安装apr-util软件包
# wget

#澳门新葡亰平台游戏网站,tar -jxvf apr-util-1.5.4.tar.bz2
#cd apr-util-1.5.4
#cd /usr/local/src/apr-util-1.5.4
#./configure –prefix=/usr/ –with-apr=/usr/
#make
#make install

3、安装pcre软件包
#wget -c

# tar -jxvf pcre-8.37.tar.bz2
#cd pcre-8.37
# ./configure –prefix=/usr/local/
#make
#make install

二、安装Apache软件包

#wget -c
#cd httpd-2.4.16
#./configure –prefix=/usr/local/apache-2.4 –enable-modules=all
–enable-mods-shared=all –enable-ssl
#make
#make install

三、开启ssl支持
1、修改vi httpd.conf 开启
LoadModule ssl_module modules/mod_ssl.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
Include conf/extra/httpd-ssl.conf

四、生成自签发证书:
# cd /usr/local/apache-2.4/conf/
#openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout
server.key -out server.crt
#根据实际情况填写国家、组织、地区、公司名生成自签发证书

五、启动Aapche软件测试。。
#/usr/local/apache-2.4/bin/apachectl start
注意防火墙开启443端口

六、Apache+Tomcat-7 联配

1、 安装JDK 略
# wget

# wget

2、安装Tomcat
# tar -zxvf apache-tomcat-7.0.64.tar.gz
# ln -s tomcat apache-tomcat-7.0.64

3、安装tomcat-connectors模块
# tar -zxvf tomcat-connectors-1.2.41-src.tar.gz
# cd tomcat-connectors-1.2.41-src
# ./ buildconf.sh
# ./configure –with-apxs=/usr/local/apache-2.4/bin/apxs
–with-tomcat=/usr/local/tomcat –with-java-home=/usr/local/jdk
–with-jni
#make
#make install

七、开启mod_jk模块

修改vi httpd.conf最后添加如下 开启 mod_jk module 支持

# Load mod_jk module
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile /usr/local/apache/conf/workers.proferties
# Where to put jk logs
JkLogFile /usr/local/apache/logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the timestamp log format
JkLogStampFormat “[%a %b %d %H:%M:%S %Y] ”

# JkRequestLogFormat set the request format
JkRequestLogFormat “%w %V %T”

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# Send servlet for context /examples to worker named worker1
#JkMount /examples/*.jsp worker1
JkMount /servlet/* worker1

# Send JSPs for context /examples to worker named worker1
JkMount /*.jsp worker1

八、新建 workers.proferties 文件

[[email protected]
conf]# more workers.proferties
workers.tomcat_home=/usr/local/tomcat
workers.java_home=/usr/local/jdk
ps=/
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.connection_pool_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.lbfactor=1
worker.inprocess.stdout=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stdout
worker.inprocess.stderr=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stderr
[[email protected]
conf]#

九、Apache+Tomcat+SSL+虚拟主机:

1、修改: httpd-ssl.conf 添加如下虚拟主机

<VirtualHost _default_:443>

# General setup for the virtual host
DocumentRoot “/www/clients/aaa.com/htdocs”
ServerName www.aaa.com:443
ServerAdmin
[email protected]
ErrorLog “/www/clients/aaa.com/logs/error_log”
TransferLog “/www/clients/aaa.com/logs/access_log”

<Directory “/www/clients/aaa.com/htdocs”>
Options -Indexes +FollowSymlinks
AllowOverride All
Require all granted
DirectoryIndex login.jsp index.jsp
</Directory>

#JkMount /examples/*.jsp worker1
JkMount /servlet/* worker1

# Send JSPs for context /examples to worker named worker1
JkMount /*.jsp worker1

# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.

SSLEngine on

SSLCertificateFile “/usr/local/apache-2.4/conf/server.crt”
SSLCertificateKeyFile “/usr/local/apache-2.4/conf/server.key”

<FilesMatch “.(cgi|shtml|phtml|php)$”>
SSLOptions +StdEnvVars
</FilesMatch>
<Directory “/usr/local/apache-2.4/cgi-bin”>
SSLOptions +StdEnvVars
</Directory>

BrowserMatch “MSIE [2-5]”
nokeepalive ssl-unclean-shutdown
downgrade-1.0 force-response-1.0

CustomLog “/usr/local/apache-2.4/logs/ssl_request_log”
“%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x “%r” %b”

</VirtualHost>

<VirtualHost _default_:443>

# General setup for the virtual host
DocumentRoot “/www/clients/bbb.com/htdocs”
ServerName www.bbb.com:443
ServerAdmin
[email protected]
ErrorLog “/www/clients/bbb.com/logs/error_log”
TransferLog “/www/clients/bbb.com/logs/access_log”

<Directory “/www/clients/bbb.com/htdocs”>
Options -Indexes +FollowSymlinks
AllowOverride All
Require all granted
DirectoryIndex login.jsp index.jsp
</Directory>

#JkMount /examples/*.jsp worker1
JkMount /servlet/* worker1

# Send JSPs for context /examples to worker named worker1
JkMount /*.jsp worker1

# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.

SSLEngine on

SSLCertificateFile “/usr/local/apache-2.4/conf/server.crt”
SSLCertificateKeyFile “/usr/local/apache-2.4/conf/server.key”

<FilesMatch “.(cgi|shtml|phtml|php)$”>
SSLOptions +StdEnvVars
</FilesMatch>
<Directory “/usr/local/apache-2.4/cgi-bin”>
SSLOptions +StdEnvVars
</Directory>

BrowserMatch “MSIE [2-5]”
nokeepalive ssl-unclean-shutdown
downgrade-1.0 force-response-1.0

CustomLog “/usr/local/apache-2.4/logs/ssl_requbbest_log”
“%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x “%r” %b”

</VirtualHost>

十、添加Tomcat虚拟主机:

1、修改:Tomcat的配置文件 server.xml 添加如下:

<Host name=”aaa.com” appBase=”webapps” unpackWARs=”true”
autoDeploy=”true”>

<Alias>www.aaa.com</Alias>

<Valve className=”org.apache.catalina.authenticator.SingleSignOn”
/>
<Valve className=”org.apache.catalina.valves.AccessLogValve”
directory=”logs”
prefix=”aaa.com_access_log.” suffix=”.txt”
pattern=”%h %l %u %t "%r" %s %b” />

<Context path=”” docBase=”/www/clients/aaa.com/htdocs”
debug=”0″ reloadable=”true”/>
</Host>

<Host name=”bbb.com” appBase=”webapps” unpackWARs=”true”
autoDeploy=”true”>

<Alias>www.bbb.com</Alias>

<Valve className=”org.apache.catalina.authenticator.SingleSignOn”
/>
<Valve className=”org.apache.catalina.valves.AccessLogValve”
directory=”logs”
prefix=”bbb.com_access_log.” suffix=”.txt”
pattern=”%h %l %u %t "%r" %s %b” />

<Context path=”” docBase=”/www/clients/bbb.com/htdocs”
debug=”0″ reloadable=”true”/>
</Host>

十一、编写测试页面:

[[email protected]
htdocs]# pwd
/www/clients/aaa.com/htdocs
[[email protected]
htdocs]# more index.jsp
<HTML>
<HEAD>
<TITLE>JSP测试页面</TITLE>
</HEAD>
<BODY>
<%out.println(“<h1>Hello wwww.aaa.com World!
</h1>”);%>
</BODY>
</HTML>
[[email protected]
htdocs]#

[[email protected]
htdocs]# pwd
/www/clients/bbb.com/htdocs
[[email protected]
htdocs]# more index.jsp
<HTML>
<HEAD>
<TITLE>JSP测试页面</TITLE>
</HEAD>
<BODY>
<%out.println(“<h1>Hello wwww.bbb.com World!
</h1>”);%>
</BODY>
</HTML>
[[email protected]
htdocs]#

十二、启动: apache、tomcat进行测试
# /usr/local/apache/bin/apachectl start
# /usr/local/tomcat/bin/startup.sh

2、修改本机主机hosts 测试

附:优化Tomcat参数:修改:catalina.sh文件 增加如下红色字
# Set juli LogManager config file if it is present and an override has
not been issued
if [ -z “$LOGGING_CONFIG” ]; then
if [ -r “$CATALINA_BASE”/conf/logging.properties ]; then
LOGGING_CONFIG=”-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties”
else
# Bugzilla 45585
LOGGING_CONFIG=”-Dnop”
fi
fi
JAVA_OPTS=”-server -Xms256m -Xmx2048m -XX:PermSize=64M
-XX:MaxNewSize=256m -XX:MaxPermSize=512m ”

+VirtualHost+自签发证书安装测试 一、安装依懒软件包 1、安装apr软件包 #
wget -c …

四.Tomcat的安装
我用的是jakarta-tomcat-4.1.30.exe安装文件,在windows下一路点”确定”就行了,比较简单,安装目录为
d:serveromcat 下面设置环境变量:
同jdk的环境变量,添加变量TOMCAT_HOME,值为d:serveromcat;增加变量CATALINA_HOME,值为
d:omcatserver,在path变量中加入d:serveromcatin
下面启动tomcat,运行tomcat目录下的,bin/startup.bat文件就行啦,出现tomcat运行控制台,tomcat成功
启动. 在IE中输入,看到大猫的吧,则tomcat安装成功.

五.安装MySQL

第一步:解压
mysql-max-3.23.46a-win.zip,运行mysql安装文件,把mysql安装到d:servermysql
第二步:在环境变量path中加入 d:servermysqlin
第三步:进入d:servermysqlin目录,运行winmysqladmin,刚会出现对话框,设置mysql用户密码,假设
帐号为:root 密码为:123
第四步:进入dos,进入mysql/bin下,运行以下命令打开mysql mysqld-nt
–standalone 则mysql开启 然后运行: mysql 如果开启,则出现以下文字:
Welcome to the MySQL monitor. Commonds end with ; or g. Your MySQL
connection id is 1 to server version: 3.23.46-nt Type help; or h for
help. Type c to clear the buffer. mysql
注意:此时mysql没有设置密码,为了不让别人进入你的数据库,请为mysql设置密码,具体操作请参阅mysql
的中文说明文档。 至此,mysql安装成功!

六.安装MySQL的驱动类jdbc
解开jdbc驱动包,把里面的org文件夹复制到jsp可以找到的位置就行啦。可以是tomcat的根目录common/classes
文件夹下,也可以是jsp网站class类WEB-INF/class/下。当加载驱动程序时,以便能找到相关的类。或者把jdbc包
的路径加入到classpath变量中。

七.Tomcat和Apache的整合配置
Tomcat只是一个用来解析*.jsp文件的容器,它不是服务器,其解析静态htm/html文件的能力远远不如apache,
整合后在同一个端口使apache来解析静态网页,而遇到*.jsp网页时,交由tomcat来解析.
第一步:把 mod_jk.dll复制到apache根目录module文件夹下。
第二步:配置APACHE

打开apache根目录下conf

添加以下语句:

#——————————————

#connecting to tomcat using ajp13 LoadModule jk_module
modules/mod_jk.dll JkWorkersFile
“d:/server/tomcat/conf/workers.properties” JkMount /servlet/* ajp13
JkMount /*.jsp ajp13

#—————————————————–

注意:以上语句的基本意思是:
loadModule一行:加载mod_jk.dll动态链接库模块,使之与tomcat通讯
jkWorkersFile:指明工作时tomcat相关文件workers.properties位置
jkMount:两行指明当遇到*.jsp和servlet时,交由ajp13协议,继而转发给tomcat处理。
第三步:建立workers.properties文件,在tomcat根目录conf下建立workers.properties文件,内容为:
workers.tomcat_home=d:serveromcat workers.java_home=d:serverj2sdk1.4.0
ps= # worker.list=ajp13 worker.list=ajp12,ajp13

worker.ajp12.port=8007 worker.ajp12.host=localhost
worker.ajp12.type=ajp12 worker.ajp12.lbfactor=1 worker.ajp13.port=8009
worker.ajp13.host=localhost worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1

worker.loadbalancer.type=lb

worker.loadbalancer.balanced_workers=ajp12, ajp13
worker.inprocess.type=jni
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)classes
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)jaxp.jar

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)parser.jar

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)jasper.jar

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)servlet.jar

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)webserver.jar

worker.inprocess.class_path=$(workers.java_home)$(ps)lib$(ps)tools.jar

worker.inprocess.cmd_line=-config

worker.inprocess.cmd_line=$(workers.tomcat_home)/conf/jni_server.xml

worker.inprocess.cmd_line=-home

worker.inprocess.cmd_line=$(workers.tomcat_home)

worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)bin$(ps)classic$(ps)jvm.dll

worker.inprocess.stdout=$(workers.tomcat_home)$(ps)inprocess.stdout

worker.inprocess.stderr=$(workers.tomcat_home)$(ps)inprocess.stderr

worker.inprocess.sysprops=tomcat.home=$(workers.tomcat_home)

注意以上文件第一、二行填上tomcat和jdk的相关目录.
第四步:配置tomca/conf下的server.xml文件,这个是tomcat的主要配置文件,重要配置如下:
1.虚拟目录设置: 找到下面内容: Host name=”localhost” debug=”0″
appBase=”/webapps” unpackWARs=”true” autoDeploy=”true” 修改为: Host
name=”localhost” debug=”0″ appBase=”d:/server/www” unpackWARs=”true”
autoDeploy=”true” 使tomcat主目录为d:server 找到下面内容: Context
path=”examples” docBase=”/examples” debug=”0″ reloadable=”true”
crossContext=”true” 修改为 Context path=”” docBase=”/” debug=”0″
reloadable=”true” crossContext=”true”
这个我的理解是应该是使tomcat根目录下的jsp作为一个虚拟主机吧.
2.设置tomcat监听端口,找到下面的内容: Connector
className=”org.apache.coyote.tomcat4.CoyoteConnector” port=”8080″
minProcessors=”5″ maxProcessors=”75″ enableLookups=”true”
redirectPort=”8443″ acceptCount=”100″ debug=”0″ connectionTimeout=”0″
useURIValidationHack=”false” disableUploadTimeout=”true” /
默认的端口是8080,但这个大家都知道,最好修改一下,假设修改为:8123,则如下:
Connector className=”org.apache.coyote.tomcat4.CoyoteConnector”
port=”8123″ minProcessors=”5″ maxProcessors=”75″ enableLookups=”true”
redirectPort=”8443″ acceptCount=”100″ debug=”0″ connectionTimeout=”0″
useURIValidationHack=”false” disableUploadTimeout=”true” /
3.找到以下8009端口的地方,这个很重要,通过8009,tomcat与apache互相通讯,如果下面的部分
被!—-注释掉,一定要把!—-去掉. !– Define a Coyote/JK2 AJP 1.3
Connector on port 8009 — Connector
className=”org.apache.coyote.tomcat4.CoyoteConnector” port=”8009″
minProcessors=”5″ maxProcessors=”75″ enableLookups=”true”
redirectPort=”8443″ acceptCount=”10″ debug=”0″ connectionTimeout=”0″
useURIValidationHack=”false”
protocolHandlerClassName=”org.apache.jk.server.JkCoyoteHandler”/
第五步:配置tomcat的conf/web.xml文件:
类似于apache下404错误页面的配置,在最后/web-app一行之前加入以下内容:
error-page error-code404/error-code location/error/noFile.htm/location
/error-page error-page
exception-typejava.lang.NullPointerException/exception-type
location/error/error.jsp/location /error-page
第一个error-page/error-page之间的是404未找到jsp网页的错误导向页面,使之发生404错误时,
网页导向至/error/noFile.htm,也可以用类似方法添加其多的错误代码导向页面。
第二个error-page/error-page之间的是当jsp网页出现java.lang.NullPointerException导常时
导向至/error/error.jsp错误页面。那么需要在第个jsp网页中加入以下内容: %@
page errorPage=”/error/error.jsp” %
典型的error.jsp错误页面的程序写法如下: %@ page
contentType=”text/html;charset=GB2312″% %@ page isErrorPage=”true”% html
headtitle错误页面/title/head

body 出错了:/p 错误信息: %= exception.getMessage() %br

Stack Trace is : prefont color=”red”% java.io.CharArrayWriter cw = new
java.io.CharArrayWriter(); java.io.PrintWriter pw = new
java.io.PrintWriter(cw,true); exception.printStackTrace(pw);
out.println(cw.toString()); %/font/pre /body /html
当出现NullPointerException异常时tomcat会把网页导入到error.jsp,且会打印出出错信息。
第五步主要是安全考虑,在正常情况下,如果找不到网页即出现404错误或者jsp程序出错,在客户端
会列举出类似于如下的信息(以tomcat为例,resin类似): HTTP Status 404 –
/sdags.jsp


type Status report

message /sdags.jsp

description The requested resource (/sdags.jsp) is not available.


Apache Tomcat/5.0.19
这样服务器版本会被别人看到,如果完成第五步的配置,就不会出现这种情况.
第六步:配置文件
这种方法把tomcat和apache的根目录设置为同一目录,但是必须限制客户对目录下一些文件的访问,比如存入class
的web-inf,在下添加以下代码: #deny the access to WEB-INF Directory ~
“/WEB-INF/” Order allow,deny Deny from all /Directory
这样,当试图记问时,apache将会拒绝.
到此为至,tomcat和apache的整合就完成啦.重新启动tomcat和apache,
把jsp网页放到d:serverwww下,例如: html h1JSP testhr

%out.println(“Hello World!”);%

/html 存为index.jsp,在IE中输入 如果出现了 Hello World!
刚说明tomcat运行正常,在IE中输入,如果也出现 Hello World!
恭喜你!整合成功啦,你在jsp漫长艰辛的道路上迈出了一大步~!

以上整合文章我是在仓促的的时间完成的,可能有些错误。或考虑不周的地方,但是总体应该没
太大问题,我是反复使用这种方法整合成功的。如果有疑问,可以直接给我联系.
moonsbird: mail:pengw97@163.com

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图