总体思路是把jetty当做web服务器,apache作为http服务器,并以ajp为协议
1, 让apache支持ajp。
要让apache支持ajp, apache要加载mod_jk.so.
mac环境下,默认是没有mod_jk.so的,所有要下载编译:
1)到官网下载tar.gz 文件,解压之后进入文件夹,执行:
$ cd native $ ./configure CFLAGS='-arch x86_64' APXSLDFLAGS='-arch x86_64' --with-apxs=/usr/sbin/apxs $ make $ sudo make install
linux环境下:
这里是将其放到/usr/local , 安装过程可能需要 aclocal,libtool,autoheader,automake,autoconf
[root@webserver ~]# cd /usr/local/ [root@webserver local]# tar xzvf jakarta-tomcat-connectors-1.2.15-src.tar.gz [root@webserver local]# cd jakarta-tomcat-connectors-1.2.15-src/jk/native [root@webserver native]#chmod 755 buildconf.sh [root@webserver native]# ./buildconf.sh [root@webserver native]#./configure --with-apxs=/usr/sbin/apxs [root@webserver native]# make [root@webserver native]# make install [root@webserver native]# cd apache-2.0 [root@webserver native]#ll mod_jk.so
2)配置 httpd.conf
2.1) 在文件中找到,
从
<IfDefine !MACOSXSERVER> #LoadModule jk_module libexec/apache2/mod_jk.so ... </IfDefine !MACOSXSERVER>
移出来,让apache一直加载mod_jk
2.2 在文件中找到:
<IfModule mod_jk.c> ... </IfModule>
改为:
<Call name="addConnector"> </Call> .... <Call name="addConnector"> <Arg> <New class="org.eclipse.jetty.ajp.Ajp13SocketConnector"> <Set name="port">8009</Set> </New> </Arg> </Call>
以async-rest为例子
<IfModule mod_jk.c> JKWorkersFile /etc/apache2/worker.properties JKLogFile /var/log/apache2/mod_jk.log JkShmFile /var/log/apache2/jk-runtime-status JkLogLevel info JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " JkOptions +ForwardKeySize +ForwardURICompat JkMount /async-rest/* jetty </IfModule>
2.3) 添加worker.properties
worker.list=jetty worker.jetty.port=8009 worker.jetty.host=127.0.0.1 worker.jetty.type=ajp13 worker.jetty.lbfactor=1
2 让jetty支持ajp
在jetty.xml中添加:
<Call name="addConnector"> ... </Call> <Call name="addConnector"> <Arg> <New class="org.eclipse.jetty.ajp.Ajp13SocketConnector"> <Set name="port">8009</Set> </New> </Arg> </Call>
若 org.eclipse.jetty.ajp.Ajp13SocketConnector 类找不到,讲jar包复制到jetty/lib/ext下
3, 重启jetty, apache, apache默认端口为80
运行 http://localhost/async-rest/
成功
4 参考
http://www.bartbusschots.ie/blog/?p=1347
http://blog.omgmog.net/post/a-possible-solution-to-bad-interpreter-operation-not-permitted-error-on-mac-os-x-lion/ 解决: bad interpreter: operation not permitted