İçindekilerGirişİndex
YukarıİlkÖncekiSonraki YokSon
Geriİleri
Yazdır

Apache + Tomcat

Giriş

Not: Bu yapılandırma örneğinde Windows platformunda Apache 1.3.23 ve Tomcat 4.0.3 kullanılmıştır. Apache ve/veya Tomcat'in farklı versiyonları için işe yaramayabilir

Apache ve Tomcat kurulumu için hem Tomcat hem de Apache tarafında yapılması gerekenler ayrı başlıklar altında aşağıdaki gibidir:

Tomcat tarafı:

Apache tarafı:

Tomcat server.xml dosyasının düzenlenmesi

server.xml dosyası Tomcat'in yapılandırma dosyasıdır. Tomcat'i ilk kurduğunuzda hazırlanmış olarak gelir. Bu adımda Tomcat'in sadece Apache ile çalışması için gerekli ayarları yapacağız. server.xml dosyası Tomcat dizini altındaki conf dizini içerisindedir. Bu dosyayı açıp içeriğini aşağıdaki kısımla değiştirelim:

Göster Gizle Kopar Satır Gizle Satır Göster
  1 <Server port="8005" shutdown="SHUTDOWN" debug="0">
  2   <!-- A "Service" is a collection of one or more "Connectors" that share
  3        a single "Container" (and therefore the web applications visible
  4        within that Container).  Normally, that Container is an "Engine",
  5        but this is not required.
  6        Note:  A "Service" is not itself a "Container", so you may not
  7        define subcomponents such as "Valves" or "Loggers" at this level.
  8    -->
  9   <Service name="Tomcat-With-Apache">
 10     <!-- A "Connector" represents an endpoint by which requests are received
 11          and responses are returned.  Each Connector passes requests on to the
 12          associated "Container" (normally an Engine) for processing.
 13          By default, a non-SSL HTTP/1.1 Connector is established on port 8080.
 14          You can also enable an SSL HTTP/1.1 Connector on port 8443 by
 15          following the instructions below and uncommenting the second Connector
 16          entry.  SSL support requires the following steps (see the SSL Config
 17          HOWTO in the Tomcat 4.0 documentation bundle for more detailed
 18          instructions):
 19          * Download and install JSSE 1.0.2 or later, and put the JAR files
 20            into "$JAVA_HOME/jre/lib/ext".
 21          * Execute:
 22              %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows)
 23              $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA  (Unix)
 24            with a password value of "changeit" for both the certificate and
 25            the keystore itself.
 26          By default, DNS lookups are enabled when a web application calls
 27          request.getRemoteHost().  This can have an adverse impact on
 28          performance, so you can disable it by setting the
 29          "enableLookups" attribute to "false".  When DNS lookups are disabled,
 30          request.getRemoteHost() will return the String version of the
 31          IP address of the remote client.
 32     -->
 33     <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
 34     <!--
 35     <Connector className="org.apache.catalina.connector.http.HttpConnector"
 36                port="8080" minProcessors="5" maxProcessors="75"
 37                enableLookups="true" redirectPort="8443"
 38                acceptCount="10" debug="0" connectionTimeout="60000"/>
 39     -->
 40     <!-- Note : To disable connection timeouts, set connectionTimeout value to -1 -->
 41     <!-- Define an SSL HTTP/1.1 Connector on port 8443 -->
 42     <!--
 43     <Connector className="org.apache.catalina.connector.http.HttpConnector"
 44                port="8443" minProcessors="5" maxProcessors="75"
 45                enableLookups="true"
 46 	       acceptCount="10" debug="0" scheme="https" secure="true">
 47       <Factory className="org.apache.catalina.net.SSLServerSocketFactory"
 48                clientAuth="false" protocol="TLS"/>
 49     </Connector>
 50     -->
 51     <!-- Define an AJP 1.3 Connector on port 10009 -->
 52     <Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
 53                port="10009" minProcessors="5" maxProcessors="75"
 54                acceptCount="10" debug="0"/>
 55     <!-- Define a Proxied HTTP/1.1 Connector on port 8081 -->
 56     <!-- See proxy documentation for more information about using this. -->
 57     <!--
 58     <Connector className="org.apache.catalina.connector.http.HttpConnector"
 59                port="8081" minProcessors="5" maxProcessors="75"
 60                enableLookups="true"
 61                acceptCount="10" debug="0" connectionTimeout="60000"
 62                proxyPort="80"/>
 63     -->
 64     <!-- Define a non-SSL HTTP/1.0 Test Connector on port 8082 -->
 65     <!--
 66     <Connector className="org.apache.catalina.connector.http10.HttpConnector"
 67                port="8082" minProcessors="5" maxProcessors="75"
 68                enableLookups="true" redirectPort="8443"
 69                acceptCount="10" debug="0"/>
 70     -->
 71     <!-- An Engine represents the entry point (within Catalina) that processes
 72          every request.  The Engine implementation for Tomcat stand alone
 73          analyzes the HTTP headers included with the request, and passes them
 74          on to the appropriate Host (virtual host). -->
 75     <!-- Define the top level container in our container hierarchy -->
 76     <Engine name="Standalone" defaultHost="localhost" debug="0">
 77       <!-- The request dumper valve dumps useful debugging information about
 78            the request headers and cookies that were received, and the response
 79            headers and cookies that were sent, for all requests received by
 80            this instance of Tomcat.  If you care only about requests to a
 81            particular virtual host, or a particular application, nest this
 82            element inside the corresponding <Host> or <Context> entry instead.
 83            For a similar mechanism that is portable to all Servlet 2.3
 84            containers, check out the "RequestDumperFilter" Filter in the
 85            example application (the source for this filter may be found in
 86            "$CATALINA_HOME/webapps/examples/WEB-INF/classes/filters").
 87            Request dumping is disabled by default.  Uncomment the following
 88            element to enable it. -->
 89       <!--
 90       <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
 91       -->
 92       <!-- Global logger unless overridden at lower levels -->
 93       <Logger className="org.apache.catalina.logger.FileLogger"
 94               prefix="catalina_log." suffix=".txt"
 95               timestamp="true"/>
 96       <!-- Because this Realm is here, an instance will be shared globally -->
 97       <Realm className="org.apache.catalina.realm.MemoryRealm"/>
 98       <!-- Replace the above Realm with one of the following to get a Realm
 99            stored in a database and accessed via JDBC -->
100       <!--
101       <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="99"
102              driverName="org.gjt.mm.mysql.Driver"
103           connectionURL="jdbc:mysql://localhost/authority?user=test;password=test"
104               userTable="users" userNameCol="user_name" userCredCol="user_pass"
105           userRoleTable="user_roles" roleNameCol="role_name" />
106       -->
107       <!--
108       <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="99"
109              driverName="oracle.jdbc.driver.OracleDriver"
110           connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL?user=scott;password=tiger"
111               userTable="users" userNameCol="user_name" userCredCol="user_pass"
112           userRoleTable="user_roles" roleNameCol="role_name" />
113       -->
114       <!--
115       <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="99"
116              driverName="sun.jdbc.odbc.JdbcOdbcDriver"
117           connectionURL="jdbc:odbc:CATALINA"
118               userTable="users" userNameCol="user_name" userCredCol="user_pass"
119           userRoleTable="user_roles" roleNameCol="role_name" />
120       -->
121       <!-- Define the default virtual host -->
122       <Host name="localhost" debug="0" appBase="c:/Apache/htdocs" unpackWARs="true">
123         <!-- Normally, users must authenticate themselves to each web app
124              individually.  Uncomment the following entry if you would like
125              a user to be authenticated the first time they encounter a
126              resource protected by a security constraint, and then have that
127              user identity maintained across *all* web applications contained
128              in this virtual host. -->
129         <!--
130         <Valve className="org.apache.catalina.authenticator.SingleSignOn"
131                    debug="0"/>
132         -->
133         <!-- Access log processes all requests for this virtual host.  By
134              default, log files are created in the "logs" directory relative to
135              $CATALINA_HOME.  If you wish, you can specify a different
136              directory with the "directory" attribute.  Specify either a relative
137              (to $CATALINA_HOME) or absolute path to the desired directory.
138         -->
139         <Valve className="org.apache.catalina.valves.AccessLogValve"
140                  directory="logs"  prefix="localhost_access_log." suffix=".txt"
141                  pattern="common"/>
142         <!-- Logger shared by all Contexts related to this virtual host.  By
143              default (when using FileLogger), log files are created in the "logs"
144              directory relative to $CATALINA_HOME.  If you wish, you can specify
145              a different directory with the "directory" attribute.  Specify either a
146              relative (to $CATALINA_HOME) or absolute path to the desired
147              directory.-->
148         <Logger className="org.apache.catalina.logger.FileLogger"
149                  directory="logs"  prefix="localhost_log." suffix=".txt"	        timestamp="true"/>
150         <!-- Define properties for each web application.  This is only needed
151              if you want to set non-default properties, or have web application
152              document roots in places other than the virtual host's appBase
153              directory.  -->
154         <!-- Tomcat Root Context -->
155         <Context path="" docBase="" debug="0"/>
156       </Host>
157     </Engine>
158   </Service>
159 </Server>

Aşağıdaki kısımda c:/Apache/htdocs'u Apache'nin sizin kurulumunuzdaki web kök dizini ile değiştirin.


 <!-- Define the default virtual host -->
      <Host name="localhost" debug="0" appBase="c:/Apache/htdocs" unpackWARs="true">

Böylece Tomcat'e Java Servlet ve JSP'lerini Apache'nin web kök dizini içerisinde arayacaktır.

Not: Bunu mevcut server.xml üzerinde bir kısım değişiklikler yaparak da elde etmek mümkündür. Zaten dikkat edilirse içeriğin çoğunluğu aynıdır. Fakat burada açıklanmasının kafa karıştırabileceğini düşündüğümden hazır halini veriyorum.

Tomcat worker.properties dosyasının düzenlenmesi

Tomcat, Apache'den gelen istekleri arkada çalışan worker isimli bir işlem ile çalıştırır. worker.properties dosyası bunun için gerekli yapılandırma değişkenlerinin tanımlandığı yerdir. Bu dosyayı elle üretmemiz gerekir. Bunun için Tomcat'i kurduğumuz dizin altındaki conf dizini altında açmış olduğumuz jk dizinine giderek worker.properties isminde bir dosya üretelim. Bu dosya içerisine şunları yazalım:


#
# worker.tomcat_home tomcat'i kurduğunuz dizini göstermeli. Mesela: C:\Tomcat4Apache gibi
#
worker.tomcat_home={beni-değiştir}

#
# worker.java_home java platform'unu kurduğunuz dizini göstermeli. Mesela: C:\jdk1.4.0 gibi.
#
worker.java_home={beni-değiştir}

#
# Dizinleri ayırmak için kullanılan karakter NT için: \, UNIX için: /
#
ps=\

#
# Tomcat'in kullandığı worker'ların isim listesi. Bizim örneğimizde
# bir tane var onu yazmamız gerekir. Birden fazla olduğu durumlarda
# virgül (,) ile ayrılır. 
#
worker.list=myTomcatWorker

#
# worker tipi, portu ve dinleyeceği host isimleri.
# Biz bu örnek için sadece  ajp13 isimli tip ile ilgileniyoruz. AJP Tomcat ile
# web sunucularının konuşurken kullandığı protokol. ajp13 -> AJP v1.3 protokolu
#
# port numarası daha sonra server.xml'de tanımlayacağımız AJP protokol sunucusunun 
# istekleri dinlediği port numarası
#
worker.myTomcatWorker.type=ajp13
worker.myTomcatWorker.port=10009
worker.myTomcatWorker.host=localhost

mod_jk.dll dosyasının kopyalanması

Apache'ye gelen Java Servlet ve JSP isteklerinin Tomcat'e iletilmesi için bir Apache modulu kullanılır. mod_jk.dll bu işi yapan modul dosyasıdır. Öncelikle yapmamız gereken mod_jk.dll dosyasını Apache'yi kurduğumuz dizin altındaki libexec dizinine kopyalamaktır. Mesela: C:\Apache\libexec

httpd.conf dosyasının düzenlenmesi

httpd.conf dosyası Apache'nin yapılandırma dosyasıdır ve Apache'yi kurduğunuz dizin altındaki conf dizininde bulunur. Mesela: C:\Apache\conf. Tomcat ile Apache'yi birlikte çalıştırmak için bu dosyayı düzenlememiz gerekmektedir. Bu dosya içerisinde yapılması gereken değişiklikler:

1 .Yaklaşık olarak 200. satırda LoadModule direktiflerinin hemen altına şu satırları ekleyin:


<IfModule !mod_jk.c>
  LoadModule jk_module libexec/mod_jk.dll
</IfModule>
JkWorkersFile "C:/Tomcat4Apache/conf/jk/worker.properties"
JkLogFile "C:/Tomcat4Apache/logs/mod_jk.log"
JkLogLevel info

Burada JkWorkersFile "C:/Tomcat4Apache/conf/jk/worker.properties" mod_jk'nın kullanacağı worker.properties dosyasının yerini belirtir. Buradaki değeri Tomcat'i kurduğunuz dizin ile değiştirmeniz gerekir.

JkLogFile "C:/Tomcat4Apache/logs/mod_jk.log" ise mod_jk'nın nereye olayları kaydedeceğini belirtir. Bu değeri de kendi Tomcat kurulumuza göre ayarlamanız gerekir.

2 .Yaklaşık olarak 255. satırda AddModule direktiflerinin hemen altına şu satırı ekleyin:

AddModule mod_jk.c

3 .Yaklaşık olarak 300. satırda DocumentRoot direktifinin altına şu satırları elkeyin:


JkMount /*.jsp myTomcatWorker
JkMount /servlet/* myTomcatWorker

<Location /WEB-INF>
    Options None
    AllowOverride None
    order deny,allow
    deny from all
</Location>

<IfModule mod_dir.c>
    DirectoryIndex index.jsp
</IfModule>

Burada:

Dosya Listesi

İçindekilerGirişİndex
YukarıİlkÖncekiSonraki YokSon
Geriİleri
Yazdır