配置tomcat+apache

1、Tomcat配置: /opt/apps/acc/cas/*

bin/start.sh
bin/stop.sh
conf/catalina.policy
conf/catalina.properties
conf/logging.properties
conf/server.xml
conf/web.xml
lib/
logs/
temp/
webapps/ROOT/
work/

start.sh

export JAVA_HOME=/usr/java/latest
export CATALINA_HOME=/usr/local/tomcat
export CATALINA_BASE=/opt/apps/acc/cas
export CATALINA_PID=${CATALINA_BASE}/tomcat.pid

${CATALINA_HOME}/bin/catalina.sh start 

stop.sh

 

export JAVA_HOME=/usr/java/latest
export CATALINA_HOME=/usr/local/tomcat
export CATALINA_BASE=/opt/apps/acc/cas
export CATALINA_PID=${CATALINA_BASE}/tomcat.pid

${CATALINA_HOME}/bin/catalina.sh stop

 

server.xml

<?xml version='1.0' encoding='utf-8'?>
<Server port="9019" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JasperListener" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <Service name="Catalina">
    <Connector port="9015" protocol="HTTP/1.1" enableLookups="false" />
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />
      </Host>
    </Engine>
  </Service>
</Server>

2、Apache配置:

/usr/local/apache2/conf/extra/httpd-vhosts.conf

# Site: Account
LISTEN 15013
<VirtualHost *:15013>
    ServerName 11.22.33.44
    DocumentRoot /opt/apps/acc/cas/webapps/ROOT/
    <Directory "/opt/apps/acc/cas/webapps/ROOT">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
        FileETag None
    </Directory>
    ProxyPass /cache.appcache !
    ProxyPass /favicon.ico !
    ProxyPass /css/ !
    ProxyPass /images/ !
    ProxyPass /img/ !
    ProxyPass /js/ !
    ProxyPass /pic/ !
    ProxyPass /theme/ !
    ProxyPass /res/ !
    AddOutputFilter DEFLATE css 
    AddOutputFilter DEFLATE htm html shtml xhtml 
    AddOutputFilter DEFLATE js 
    AddOutputFilter DEFLATE txt text 
    AddOutputFilterByType DEFLATE text/html
    ProxyPass / http://127.0.0.1:5015/
    ProxyPassReverse / http://127.0.0.1:5015/
    ProxyPreserveHost On
    RequestHeader set X-Forwarded-Proto HTTP
</VirtualHost>

因为tomcat使用的是http, <Connector port="9015" protocol="HTTP/1.1" enableLookups="false" />

所以apache使用的ProxyPass也是http, ProxyPass / http://127.0.0.1:5015/

如果tomcat使用的是AJP, <Connector port="5015" protocol="AJP/1.3" enableLookups="false" />

则apache使用的ProxyPass使用的是ajp, ProxyPass / ajp://127.0.0.1:5015/

重启apache使用:

/usr/local/apache2/bin/apachectl restart

补充,如果是配置HTTPS,写法如下:

LISTEN 6443
<VirtualHost *:6443>
    ServerName t-id.gionee.com
    DocumentRoot /opt/apps/acc/cas/webapps/ROOT/
    <Directory "/opt/apps/acc/cas/webapps/ROOT">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
        FileETag None
    </Directory>
    ProxyPass /cache.appcache !
    ProxyPass /favicon.ico !
    ProxyPass /css/ !
    ProxyPass /images/ !
    ProxyPass /img/ !
    ProxyPass /js/ !
    ProxyPass /pic/ !
    ProxyPass /theme/ !
    AddOutputFilter DEFLATE css 
    AddOutputFilter DEFLATE htm html shtml xhtml 
    AddOutputFilter DEFLATE js 
    AddOutputFilter DEFLATE txt text 
    AddOutputFilterByType DEFLATE text/html
    ProxyPass / ajp://127.0.0.1:5015/
    ProxyPassReverse / ajp://127.0.0.1:5015/
    ProxyPreserveHost On
    RequestHeader set X-Forwarded-Proto HTTPS
    SSLEngine on
    SSLCertificateFile "/usr/local/apache/conf/t-id.xxx.com.crt"
    SSLCertificateKeyFile "/usr/local/apache/conf/t-id.xxx.com.key"
    SSLCACertificateFile "/usr/local/apache/conf/ca.crt"
</VirtualHost>

 

posted @ 2012-11-30 11:54  chenjunbiao  阅读(542)  评论(0编辑  收藏  举报