php tomcat配置_如何在同一台服务器的环境下运行PHP和Tomcat?

Asked this on AskUbuntu a while ago:

http://askubuntu.com/questions/630897/apache-httpd-backed-by-both-tomcat-and-php

but no answers there so I decided to ask here.

Once again - let's say I have server accessible by some domain name e.g. http://mywebapp.com/

I would like to setup the following on that server:

all requests like http://mywebapp.com/blog* are handled by PHP server (Wordpress blog engine to be specific)

all other requests http://mywebapp.com/* are handled by Apache Tomcat

I thought that this could be achievable by putting Apache HTTPD server in front of both Tomcat and PHP servers but couldn't find configurations to achieve this.

Could someone please provide any hint on how to achieve this?

解决方案

You can do that with mod_jk:

1) Enable module "mod_jk" in your Apache web servers httpd.conf. Uncomment this line, by removing the leading hash:

LoadModule jk_module modules/mod_jk.so

If you are on Linux type:

sudo apt-get install libapache2-mod-jk

sudo a2enmod jk

2) Edit [TOMCAT_DIR]/conf/server.xml. Add a "jvmRoute" attribute to the "engine" element:

Uncomment the AJP connector (the http connector may be disabled):

3) Create a file "workers.properties", next to "httpd.conf". Add this content and set right ip/port:

worker.list=tomcat

worker.tomcat.type=ajp13

worker.tomcat.host=127.0.0.1

#This is the port from the AJP connector, not HTTP!

worker.tomcat.port=8009

worker.tomcat.lbfactor=10

4) Add this mapping at the end of httpd.conf and replace [PATH_TO_DIR] by the absolute path:

JkWorkersFile [PATH_TO_DIR]\workers.properties

JkLogFile [PATH_TO_DIR]\mod_jk.log

JkLogLevel INFO

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

SetEnvIf Request_URI "/error/*" no-jk

SetEnvIf Request_URI "/blog*" no-jk

JkMount / tomcat

JkMount /* tomcat

5) Start Tomcat and restart Httpd.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值