天高云淡 发表于 2017-1-1 07:44:36

apache & jboss 简单整合

  简单整合apache 和 jboss 步骤如下(暂不考虑集群之类): 
  参考:
  http://man.chinaunix.net/newsoft/jboss.htm


    http://www.itlearner.com/code/apache2.2/vhosts/index.html

  首先配置apache,在conf 目录下,建立mod_jk.conf文件,内容如下:
  LoadModule jk_module modules/mod_jk.so


JkWorkersFile /usr/local/apache2/conf/workers.properties
JkLogFile logs/mod_jk.log
# Set the jk log level
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
JkMount /servlet/*worker1
JkMount /*.jsp worker1
#JkMount /* loadbalancer
#apache will serve the static picture.
#以下命令意味着所有的图片将由APACHE解析
#JkUnMount /*.jpg loadbalancer
#JkUnMount /*.gif loadbalancer
#JkUnMount /*.swf loadbalancer
#JkUnMount /*.bmp loadbalancer
#JkUnMount /*.png loadbalancer
   建立worker.properties  内容如下:

#worker.list=loadbalancer,server105,server106
worker.list=worker1
# Set properties for worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300

# Define the first node...
#worker.server105.port=9090
#worker.server105.host=127.0.0.1
#worker.server105.type=ajp13
#worker.server105.lbfactor=1
##worker.server105.local_worker=1
#worker.server105.cachesize=100
# Define the 2nd node...
#worker.server106.port=9090
#worker.server106.host=127.0.0.1
#worker.server106.type=ajp13
#worker.server106.lbfactor=1
#worker.server106.local_worker=1
#worker.server106.cachesize=100
# Now we define the load-balancing behaviour
#worker.loadbalancer.type=lb
#worker.loadbalancer.balanced_workers=server105,server106
#worker.loadbalancer.sticky_session=1
 
   最后需要在httpd.conf 加入:




Include conf/mod_jk2.conf


 

    这时候启动会报找不到mod_jk.so的错误,需要手工生成,先去http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/source/ 这个地址下载个jakarta-tomcat-connectors-jk-1.2.6-src.tar.tar 

    然后就可以编译生成:

     


# tar xzvf jakarta-tomcat-connectors-jk-1.2.6-src.tar.tar
# cd jakarta-tomcat-connectors-jk-1.2.6-src/jk/native
# ./configure --with-apxs=/usr/local/apache2/bin/apxs
# make
# cp ./apache-2.0/mod_jk.so /usr/local/apache2/modules/

  到这里apache 部分配置完成,接下来jboss,其实jboss都不用配置,修改个端口,别跟apache端口冲突就可以了,默认是8080,改个9090之类的就可以,配置文件在jboss-4.0.5.GA/server/default/deploy/jbossweb-tomcat55.sar/server.xml 。
  到这里完成啦,搞一个war包,里面简单弄个jsp文件,源码比如:

Hello ~~~~
图片:<img src="10.jpg"/>
  把war放到jboss default/deploy目录下,启动jboss  和 apache ,通过apache端口访问war包内的jsp文件试试,可以了吧~~
  然后问题来了, 我的html文件是放在apache处,war包名为Test,那我访问工程文件是http://www.test.com:8080/Test/index.html,但是这样是访问不到的,因为mod的规则是,selvet和jsp是跳转到jboss,html是在apache,但是apache没有建立Test目录,怎么样让他跳转到apache处指定目录下的同名静态文件呢?
  需要在httpd.con 对应的VirtualHost中加上RewriteRule ^/WebTest/(.*).html /$1.html , 这样访问就会跳转了。
  同样的,在jsp中使用的jpg文件,需要跳转到apache的默认目录,则需要加上RewriteRule ^/WebTest/(.*).jpg /$1.jpg ;
  完整的httpd.conf VirtualHost配置:

<VirtualHost *>
ServerAdmin sefer@xiaofeng.com
DocumentRoot /usr/local/apache2/htdocs/sefer
ServerName www.test.com
ErrorLog logs/test.sefer.com-error_log
TransferLog logs/test.sefer.com-access_log
RewriteEngine On
RewriteRule /test/(.*) /index.html
RewriteRule /out/(.*) http://www.163.com
RewriteRule ^/WebTest/(.*).html /$1.html
RewriteRule ^/WebTest/(.*).jpg /$1.jpg
</VirtualHost>
  这样图片也能出来了,访问http://www.test.com:8080/WebTest/index.html 直接跳转到http://www.test.com:8080/index.jsp。
页: [1]
查看完整版本: apache & jboss 简单整合