apache + tomcat 域名問題

apache+tomcat的域名配置

問題描述:apache已經佔用服務器的80端口,如今tomcat上臨時公開帶有域名的的幾個web項目 方法一:apache + tomcat ----mod-jk的方式php

  • 因爲在tomcat的上直接配域名訪問的話必須帶tomcat的端口(apache已經佔用80端口),不能接受域名+接口的模式 附上配置方法:
  1. 下載Tomcat Connectors (mod_jk),鏈接以下:http://tomcat.apache.org/download-connectors.cgi
  2. 編譯安裝mod_jk 生成 mod_jk.so,生成方法上面鏈接裏有詳細過程
  3. 配置文件 :apache配置文件尾部增長下面兩句配置 emacs apache2/conf/httpd.conf
# Note: add by livend for tomcat-connector
LoadModule jk_module modules/mod_jk.so
Include /home/ap/apache2/conf/mod_jk.conf```
    mod_jk.conf文件示例:

指出mod_jk模塊工做所須要的工做文件workers.properties的位置

JkWorkersFile /home/ap/apache2/conf/workers.propertiesjava

Where to put jk logs

JkLogFile /home/ap/apache2/logs/mod_jk.lognginx

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

JkLogLevel infoweb

Select the log format

JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"apache

JkOptions indicate to send SSL KEY SIZE,

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectoriestomcat

JkRequestLogFormat set the request format

JkRequestLogFormat "%w %V %T"服務器

將全部servlet 和jsp請求經過ajp13的協議送給Tomcat,讓Tomcat來處理

#JkMount /servlet/* worker1 #JkMount /.jsp worker1 JkMount / worker1app

workers.properties示例:

Defining a worker named worker1 and of type ajp13

#worker.list=worker1webapp

Set properties for worker1

#worker.worker1.type=ajp13 #worker.worker1.host=localhost #worker.worker1.port=8443 #worker.worker1.lbfactor=50 #worker.worker1.cachesize=10 #worker.worker1.cache_timeout=600 #worker.worker1.socket_keepalive=1 #worker.worker1.socket_timeout=300socket

workers.tomcat_home=/home/ap/apache-tomcat-7.0.54 workers.java_home=/home/ap/jdk1.7.0_68 ps=/ worker.list=worker1 worker.worker1.port=8009 worker.worker1.host=localhost worker.worker1.type=ajp13 worker.worker1.connection_pool_timeout=600 worker.worker1.socket_keepalive=1 worker.worker1.lbfactor=1 worker.inprocess.stdout=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stdout worker.inprocess.stderr=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stderr

在apache下配置域名
問題:tomcat web中配置的絕對路徑沒法被識別,找了不少資料沒有找到好辦法

**方法二:apache轉發**
- 一直用的nginx轉發,居然不知道apache也能轉發端口
- 直接記錄配置文件示例:http-vhost.conf (域名配置在tomcat server.xml中,後面附上事例)

<VirtualHost *:80> ServerName www.aaa.com #ServerAlias aaa.com *.aaa.com ProxyPass / http://www.aaa.com:8080/ ProxyPassReverse / http://www.aaa.com:8080/ ErrorLog logs/mall-error_log CustomLog logs/mall-access_log common </VirtualHost>

_這裏實際訪問的是http://www.aaa.com:8080,也不存在任何問題,其實用ngix轉發也能夠,但是個人ngix被php用掉了,最主要的是,不是80端口;_
**要注意若是配置二級域名的時候,二級域名要先主域名配置,不然子域名沒法訪問
像這樣

<VirtualHost *:80> ServerName port.aaa.com #ServerAlias aaa.com *.aaa.com ProxyPass / http://port.aaa.com:8080/ ProxyPassReverse / http://port.aaa.com:8080/ ErrorLog logs/mall-error_log CustomLog logs/mall-access_log common </VirtualHost> <VirtualHost *:80> ServerName www.aaa.com #ServerAlias aaa.com *.aaa.com ProxyPass / http://www.aaa.com:8080/ ProxyPassReverse / http://www.aaa.com:8080/ ErrorLog logs/mall-error_log CustomLog logs/mall-access_log common </VirtualHost>

**

tomcat 配域名的事例:在<engine></engine>標籤中配置一個host標籤

<Host name="www.aaa.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="aaa." suffix=".log" pattern="%h %l %u %t &quot;%r&quot; %s %b" /> <Context path="" docBase="aaa" debug="0" reloadable="true"/> </Host>

相關文章
相關標籤/搜索