Combination of Apache, Tomcat, port 80, 8080 and other stuff
I have a Centos5 with running httpd, mysql and tomcat6. All fine. My goal is to achieve the following
www.domain.com >>> forwards/proxies to www.domain.com:8080/myapplication (served by tomcat) www.domain.com/phpmyadmin >>> www.domain.com/phpmyadmin (served by Apache from htdocs) www.domain.com/* >>> also serverd by htdocs 开发者_开发知识库folder as "normal" Apache content
How can I achieve this? Any ideas?
THX
Your only deviation from apache serving htdocs seems to be sending stuff to tomcat, which is running a servlet "myappplication". In this case,
- Define a worker (some text string, lets call it "myworker").
- Near the end of file /etc/apache2/apache2.conf, add the lines
--Ignore this line in the post--
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
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 /myapplication/* myworker
In that directory, create a file "workers.properties", that contains the following:
worker.myworker.type=ajp13 worker.myworker.host=localhost worker.myworker.port=8081 worker.myworker.cachesize=10 worker.myworker.cache_timeout=600 worker.myworker.socket_keepalive=1 worker.myworker.socket_timeout=300
Edit the line tomcat_inst_dir/conf/server.xml to put in a line
[Connector port="8081" protocol="AJP/1.3" /]
Note: change the square brackets to angle brackets. The above line goes inside the [service]...[/Service] tags and out of the [Engine] ... [/Engine] tags, put it right above the [Engine] line.
- Restart apache and tomcat
Now any request to "http://www.domain.com/myapplication/servletName[?par=value...]" gets redirected by apache (on port 80) to tomcat (on port 8081) and on to the servlet myapplication. I assume you have a directory "tomcat_home/webapps/myapplication", which in turn has a directory WEB-INF with a "web.xml" file in it. "servletName" above is what you define between the [servlet-name]...[/servlet-name] tags in that file.
I chose the number 8081 (feel free to choose your port number as long as it doesnt conflict with other standard services) so that port 8080 is still active for you to test "http://www.domain.com:8080/myapplication/servletName" (should produce same output on ports 8080 and 80, the apache port).
IMPORTANT: Keep a backup copy of all the files changed in the above process, so you can revert back to your working system if the above doesn't work. I had to go through countless iterations of the above to get it working!
Good luck, and hope this works out for you, - M.S.
PS. Sorry about the formatting - I couldnt get this any better
Have your index file in www.domain.com redirect to www.domain.com:8080/myapplication. Example index.php:
<?php
header("Location: http://www.domain.com:8080/myapplication");
?>
Not the cleanest or most elegant way but it works. The elegant approach would be to use vhosts in apache.
精彩评论