在Ubuntu上实现Tomcat Apache的连接

这是一件简单的事情,但由于很少去做,所以我写下来作为备忘录。

我参考了http://www.adminweb.jp/apache/tomcat/的内容,并成功地在Ubuntu上进行了替换操作。非常感谢。

请假我已成功安装并运行了Tomcat。

Tomcat的配置

如果在Ubuntu10上通过默认方式安装Tomcat6,那么应该会在/etc/tomcat6目录下有相应的配置。在此前提下继续。

杀死下面这个

    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <!--<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               URIEncoding="UTF-8"
               redirectPort="8443" /> -->

充分利用以下的信息。

     <!-- Define an AJP 1.3 Connector on port 8009 -->
     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

重新启动Tomcat。

sudo /etc/init.d/tomcat6 restart

Apache的配置

利用mod_proxy和mod_proxy_ajp

sudo a2enmod proxy
sudo a2enmod proxy_ajp

因为这次我想用虚拟主机来连接,所以新建了一个网站设置。
内容可以如下所示。

<VirtualHost *:80>
        ServerName xxx.com # ドメイン
        ServerAdmin admin@xxx.com # 管理者のメール

        <Location />
           ProxyPass ajp://localhost:8009/
           Order allow,deny
           Allow from all
        </Location>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
</VirtualHost>

启用站点并重新启动Apache。

sudo a2ensite [SiteName]
sudo /etc/init.d/apache2 restart

如果能够访问xxx.com并显示Tomcat的根目录,那就可以了。

广告
将在 10 秒后关闭
bannerAds