构建Linux下的Resin + Apache + jsp
参考:http://blog.chinaunix.net/uid-29140694-id-4018236.html
如果你的网站是建立在apache下现在又想使用jsp,怎么办呢?你可以通过一些支持apache的jsp引擎(如resin,tomcat,jser等)来实现。这里介绍怎么配置apache+resin使apache支持jsp。
为什么要整合resin和apache,已经整合的好处如下:
a.动静分离
b.早起的resin、tomcat的http服务不太好
c.早期的resin、tomcat对rewrite和expire功能不太好
系统环境centos7.2
1、首先安装apache
(1)下载apache,下载地址为:http://archive.apache.org/dist/httpd/
(2)tar zxvf httpd-2.2.26.tar.gz
(3)cd httpd-2.2.26
(4)./configure --prefix=/usr/local/httpd --enable-module=so
(5)make && make install
(6)apache安装完成后,进入/usr/local/httpd/bin/目录下,执行./apachecl start命令启动apache
(7)访问http://127.0.0.1/页面查看apache服务是否安装正常。
如果安装./configure中出现:
error: no acceptable C compiler found in $PATH
请先安装gcc
yum install gcc
2、安装Resin
(1)下载resin,下载地址为:http://www.caucho.com/download/resin-4.0.25.tar.gz
(2)tar zxvf resin-4.0.25.tar.gz
(3)cd resin-4.0.25
(4)./configure --prefix=/usr/local/resin --enable-64bit --with-apxs=/usr/local/httpd/bin/apxs (安装resin需指明apache的安装目录)
(5)make && make install
(6)进入apache目录 /usr/local/httpd/conf/目录下,查看httpd.conf文件如果发现以下内容,则表示整合成功。
6800是resin默认的真正的端口号,如果resin修改了,这里也得修改
LoadModule caucho_module /usr/local/httpd/modules/mod_caucho.so
ResinConfigServer localhost 6800
CauchoConfigCacheDirectory /tmp
CauchoStatus yes
报错一(我还没安装jdk)
configure: error:
*** Can't find JNI directory in JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64/jre/bin
*** JNI is expected in /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64/jre/bin/include/linux
报错二(jdk配置不全,报的错)
checking for JAVA_HOME... /usr/local/jdk1.8
configure: error: Can't find valid JAVA_HOME /usr/local/jdk1.8
解决(重新正确配置好即可)
https://blog.csdn.net/xiao__jia__jia/article/details/85079606
报错
OPENSSL : No OpenSSL has been found
*** OpenSSL libraries cannot be compiled ***
先执行安装
yum -y install openssl openssl-devel
3、apache与resin的配置
(1)修改apache配置文件/usr/local/httpd/conf/httpd.conf修改其工程目录:
DocumentRoot "/data/resin"
<Directory "/data/resin">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
修改完apache之后,同时修改resin的配置文件/usr/local/resin/conf/resin.xml 将以下部分中的root-directory改为你的工程目录与apache的工程目录相同。
<host id="" root-directory=".">
<web-app id="/" root-directory="/data/resin"/>
<resin:if test="${resin_doc}">
<web-app id="/resin-doc" root-directory="${resin.root}/doc/resin-doc"/>
</resin:if>
</host>
4、服务测试
(1)将你的 index.jsp页面 放到/data/resin/test目录下。
(2)进入resin目录/usr/local/resin/bin目录下执行./resinctl restart命令重启resin服务。
(3)访问http://127.0.0.1:8080/index.jsp可访问到index.jsp页面,说明resin服务配置正常。
[root@mylinuxclone bin]# curl http://127.0.0.1:8080/test/index.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
hello world!Wanjia
</body>
</html>
(4)进入apache目录/usr/local/httpd/bin目录下执行./apachectl restart命令重启apache服务。
(5)同样访问http://127.0.0.1/test/index.jsp ,此时的端口号为apache的端口号,发现apache也可以解析jsp文件了,整合成功。
当一个静态请求来了,apache自己就处理了,如果是动态页面,就转发给resin。
[root@mylinuxclone bin]# curl http://127.0.0.1/test/index.jsp
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /test/index.jsp
on this server.</p>
</body></html>
apache权限不够。
解决方法:
修改apache的httpd.conf
另外:可以通过修改apache的配置文件httpd.conf中的DirectoryIndex,将index.jsp加入进去,则可通过访问http://127.0.0.1/test/ 的方式访问web工程了。