The Jakarta Project
      The Tomcat Servlet/JSP Container

リンク

はじめに

管理者

アプリケーション開発者

Catalina開発者

Jasper開発者

Proxy Support HOW-TO

Introduction はじめに

Using standard configurations of Tomcat, web applications can ask for the server name and port number to which the request was directed for processing. When Tomcat is running standalone with the HTTP/1.1 Connector, it will generally report the server name specified in the request, and the port number on which the Connector is listening. The two servlet API calls of interest, for this purpose, are:

  • ServletRequest.getServerName()
  • ServletRequest.getServerPort()

Tomcatの標準設定を使用することでWebアプリケーションは処理のために リクエストが向けられたサーバ名とポート番号を照会することができます。 TomcatがHTTP/1.1 Connectorで スタンドアロン稼動しているときには、リクエストの中に特定したサーバ名と Connectorが開いているポート番号を通知します。 これらの目的のために呼び出される2つのServlet APIを以下にしめします。

  • ServletRequest.getServerName()
  • ServletRequest.getServerPort()

When you are running behind a proxy server (or a web server that is configured to behave like a proxy server), you will sometimes prefer to manage the values returned by these calls. In particular, you will generally want the port number to reflect that specified in the original request, not the one on which the Connector itself is listening. You can use the proxyName and proxyPort attributes on the <Connector> element to configure these values.

プロキシサーバ(もしくはプロキシサーバのようにふるまう Webサーバ)が稼動している際に、呼び出しによる値を操作したい ときがあります。特に、一般にですが開いている Connector自身ではなく、元のリクエストに 指定されているポート番号であると考えてください。 proxyNameproxyPort属性を <Connector>要素に追加し、それらの値を 設定してください。

Proxy support can take many forms. The following sections describe proxy configurations for several common cases.

プロキシサポートは多くの形体で実現します。以下のセクションでは、よくあるいくつかのプロキシの設定について説明します。

Apache 1.3 Proxy Support Apache1.3でのプロキシサポート

Apache 1.3 supports an optional module (mod_proxy) that configures the web server to act as a proxy server. This can be used to forward requests for a particular web application to a Tomcat 4 instance, without having to configure a web connector such as mod_webapp. To accomplish this, you need to perform the following tasks:

Apache1.3はWebサーバをプロキシサーバに仕立てあげるために、オプションのモジュール(mod_proxy)をサポートします。これはmod_webappのようなWeb Connectorを設定する必要がなく、Tomcat 4のインスタンスへの特殊なWebアプリケーションの転送をリクエストするために使用できます。 これを実行するには、以下を行ってください。

  1. Configure your copy of Apache so that it includes the mod_proxy module. If you are building from source, the easiest way to do this is to include the --enable-module=proxy directive on the ./configure command line.
  2. If not already added for you, make sure that you are loading the mod_proxy module at Apache startup time, by using the following directives in your httpd.conf file:
    LoadModule proxy_module  {path-to-modules}/mod_proxy.so
    AddModule  mod_proxy.c
    
  3. Include two directives in your httpd.conf file for each web application that you wish to forward to Tomcat 4. For example, to forward an application at context path /myapp:
    ProxyPass         /myapp  http://localhost:8081/myapp
    ProxyPassReverse  /myapp  http://localhost:8081/myapp
    
    which tells Apache to forward URLs of the form http://localhost/myapp/* to the Tomcat 4 connector listening on port 8081.
  4. Configure your copy of Tomcat 4 to include a special <Connector> element, with appropriate proxy settings, for example:
    <Connector className="org.apache.catalina.connector.http.HttpConnector"
                    port="8081" ...
               proxyName="www.mycompany.com"
               proxyPort="80"/>
    
    which will cause servlets inside this web application to think that all proxied requests were directed to www.mycompany.com on port 80.
  5. It is legal to omit the proxyName attribute from the <Connector> element. If you do so, the value returned by request.getServerName() will by the host name on which Tomcat is running. In the example above, it would be localhost.
  6. If you also have a <Connector> listening on port 8080 (nested within the same Service element), the requests to either port will share the same set of virtual hosts and web applications.
  7. You might wish to use the IP filtering features of your operating system to restrict connections to port 8081 (in this example) to be allowed only from the server that is running Apache.
  8. Alternatively, you can set up a series of web applications that are only available via proxying, as follows:
    • Configure another <Service> that contains only a <Connector> for the proxy port.
    • Configure appropriate Engine, Host, and Context elements for the virtual hosts and web applications accessible via proxying.
    • Optionally, protect port 8081 with IP filters as described earlier.
  9. When requests are proxied by Apache, the web server will be recording these requests in its access log. Therefore, you will generally want to disable any access logging performed by Tomcat itself.
  1. mod_proxyモジュールが含まれるようにApacheを設定してください。ソースからビルドするのであれば、最も簡単なやり方は ./configure コマンドラインに --enable-module=proxyディレクティブを加えることです。
  2. If not already added for you, make sure that you are loading the mod_proxy module at Apache startup time, by using the following directives in your httpd.conf file:
    LoadModule proxy_module  {path-to-modules}/mod_proxy.so
    AddModule  mod_proxy.c
    
    もしすでに追加されているのであれば、以下のディレクティブを httpd.conf ファイルで使用することで、Apacheの起動時に mod_proxy モジュールがロードされていることを確認してください。
    LoadModule proxy_module  {path-to-modules}/mod_proxy.so
    AddModule  mod_proxy.c
    
  3. Include two directives in your httpd.conf file for each web application that you wish to forward to Tomcat 4. For example, to forward an application at context path /myapp:
    ProxyPass         /myapp  http://localhost:8081/myapp
    ProxyPassReverse  /myapp  http://localhost:8081/myapp
    
    which tells Apache to forward URLs of the form http://localhost/myapp/* to the Tomcat 4 connector listening on port 8081. Tomcat 4に転送を行う各々のWebアプリケーションごとに、httpd.confファイルに以下の2つのディレクティブを加えてください。 context パスが /myapp であるアプリケーションを転送するには
    ProxyPass         /myapp  http://localhost:8081/myapp
    ProxyPassReverse  /myapp  http://localhost:8081/myapp
    
    これでApacheに転送先URLは http://localhost/myapp/* からポート8081で開いているTomcat Connectorまでだとしめすことができます。
  4. 正しいプロキシの設定とともに、特別な<Connector>要素を含むようにTomcat 4 を設定してください。例をあげます:
    <Connector className="org.apache.catalina.connector.http.HttpConnector"
                    port="8081" ...
               proxyName="www.mycompany.com"
               proxyPort="80"//>
    
    これでWebアプリケーション内にあるサーブレットが、プロキシのリクエストがすべてポート80の www.mycompany.com に直行することを認識することができます。
  5. <Connector>要素から proxyName 属性を省略することができます。そうした場合には、request.getServerName()はTomcat稼動しているホスト名を返すことになります。上記の例では、localhost になります。
  6. さらにポート8080で開いていてService 要素の中にネストしている<Connector>があるのであれば、両方のポートへのリクエストは仮想ホストとWebAppの同じセットを共有することになります。
  7. You might wish to use the IP filtering features of your operating system to restrict connections to port 8081 (in this example) to be allowed only from the server that is running Apache.
  8. Alternatively, you can set up a series of web applications that are only available via proxying, as follows:
    • Configure another <Service> that contains only a <Connector> for the proxy port.
    • Configure appropriate Engine, Host, and Context elements for the virtual hosts and web applications accessible via proxying.
    • Optionally, protect port 8081 with IP filters as described earlier.
  9. When requests are proxied by Apache, the web server will be recording these requests in its access log. Therefore, you will generally want to disable any access logging performed by Tomcat itself.

    When requests are proxied in this manner, all requests for the configured web applications will be processed by Tomcat (including requests for static content). You will often be able to improve performance by using the mod_webapp web connector instead, which automatically configures itself to have Apache handle static content that is not processed by filters or security constraints defined within the web application's deployment descriptor (/WEB-INF/web.xml).

  1. You might wish to use the IP filtering features of your operating system to restrict connections to port 8081 (in this example) to be allowed only from the server that is running Apache. Apacheで稼動しているサーバからのみ接続をできるように(この例での) ポート8081のように接続を限定したい場合、使用している オペレーティングシステムのIPフィルタリング機能を使用することがあるかも しれません。
  2. Alternatively, you can set up a series of web applications that are only available via proxying, as follows: もしくは以下のように一連のWebアプリケーションをプロキシ経由でのみ 使用できるようにすることが出来ます。
    • Configure another <Service> that contains only a <Connector> for the proxy port. プロキシポートのためのConnectorのみを含む他の <Service>を設定してください。
    • Configure appropriate Engine, Host, and Context elements for the virtual hosts and web applications accessible via proxying. プロキシ経由でアクセス可能な仮想ホストとWebアプリケーションのための エンジンホストコンテキストを正しく設定してください。
    • Optionally, protect port 8081 with IP filters as described earlier. オプションですが、前途のようにポート8081をIPフィルターで保護して ください。
  3. When requests are proxied by Apache, the web server will be recording these requests in its access log. Therefore, you will generally want to disable any access logging performed by Tomcat itself. リクエストがApacheによってプロキシで行われている場合、そのWebサーバは 自身のアクセスログによってリクエストが記録されています。 それゆえに、Tomcatでのログを止めたい場合がよくあります。

When requests are proxied in this manner, all requests for the configured web applications will be processed by Tomcat (including requests for static content). You will often be able to improve performance by using the mod_webapp web connector instead, which automatically configures itself to have Apache handle static content that is not processed by filters or security constraints defined within the web application's deployment descriptor (/WEB-INF/web.xml).

この方法でリクエストがプロキシで行われている場合、Webアプリケーションの ために設定されたすべてのリクエストはTomcatによって 処理されます(静的なコンテンツを含む)。しばしばApacheに、Webアプリケーションの デプロイメントディスクリプタ(/WEB-INF/web.xml)内で定義された フィルタまたはセキュリティ強制するものにより処理されない静的な内容を処理させる ために、自身を自動的に設定し代わりに、mod_webappウェブコネクタを 使って性能を改善することができます。


Copyright © 1999-2001, Apache Software Foundation