Apache-2.2

虛擬主機、apache、mod-jk 和 tomcat

  • December 20, 2014

我的 cent os 伺服器上有一個 tomcat(在 8080 上執行)應用程序,我可以使用 url 訪問它:

SERVER_IP:8080/myapp

我有我的管理面板

SERVER_IP:8080/myapp/admin

我有一個 apache 伺服器在埠 80 上執行。

我有兩個域:

www.myapp.com
admin.myapp.com

我設法配置了 tomcat、mod_jk 和 apache 伺服器,以便 admin.myapp.com url 打開 tomcat 首頁(SERVER_IP:8080)。

但我想要的是讓 admin.myapp.com url 打開 SERVER_IP:8080/myapp/admin 和 www.myapp.com 打開 SERVER_IP:8080/myapp。

我需要讓 apache 知道何時有請求到達 admin.myapp.com,它應該知道將請求重定向到 SERVER_IP:8080/myapp/admin。顯然缺少了什麼。

這是我的配置:

httpd.conf(admin.myapp.com.conf 實際上是因為它是由 plesk 面板創建的,但我認為它無關緊要)

<VirtualHost SERVER_IP:80 >
   ServerName "admin.myapp.com:80"
   ServerAlias "www.admin.myapp.com"
   ServerAlias "ipv4.admin.myapp.co"
   ServerAdmin "cuneyty@mycompany.com"
   UseCanonicalName Off

   JkMount / ajp13
   JkMount /* ajp13

   ....
</VirtualHost>

mod_jk.conf

# Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
# Update this path to match your conf directory location
JkWorkersFile /usr/local/tomcat7/conf/workers.properties

# Where to put jk logs
# Update this path to match your logs directory location
JkLogFile /usr/local/tomcat7/logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel debug

# 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"

workers.properties

# Define 1 real worker named ajp13
worker.list=ajp13

# Set properties for worker named ajp13 to use ajp13 protocol,
# and run on port 8009
worker.ajp13.type=ajp13
worker.ajp13.host=localhost
worker.ajp13.port=8009
worker.ajp13.lbfactor=50
worker.ajp13.cachesize=10
worker.ajp13.cache_timeout=600
worker.ajp13.socket_keepalive=1
worker.ajp13.socket_timeout=300

提前致謝。

我已經想出使用 mod_proxy 而不是 mod_jk 並添加這些行:

ProxyPass / http:// SERVER_IP:8080/ 
ProxyPass /myapp/ http:// SERVER_IP:8080/myapp

而這行 cookie :

ProxyPassReverseCookiePath /myapp /"

引用自:https://serverfault.com/questions/653712