Help us understand the problem. What is going on with this article?

Apache2.4+Tomcat8をAJPプロトコルで連携してJSPを表示

More than 3 years have passed since last update.

作業メモです。

環境

  • Amazon Linux AMI 2016.03.2 (HVM)
  • Apache2.4
  • Tomcat8

Apache2.4

$sudo yum install httpd24 -y
$sudo service httpd start

# 確認
$curl http://localhsot/

Tomcat8

今回はサンプルアプリ用のwarファイルをTomcatのページよりダウンロードして使っています

Sample Application

$sudo yum install tomcat8 -y
$sudo su
$cd /usr/share/tomcat8/webapps/
$wget https://tomcat.apache.org/tomcat-8.0-doc/appdev/sample/sample.war
$service tomcat8 start

# 確認
$curl http://localhost:8080/sample/

AJPを使ってApachとTomcatを連携

Apache2.4とTomcat8を連携させる

初めにTomcat側の設定でAJP ConnectorがLISTENになっていることを確認

#Connector port 確認
$grep  AJP  /etc/tomcat8/server.xml
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

# 8009ポートでLISTENしていることを確認
$sudo netstat -lanput |grep 8009
   tcp        0      0 :::8009                     :::*                        LISTEN      3310/java

次にApache側の確認

モジュール読み込みの確認

# mod_proxy.so 及び mod_proxy_ajp.so の読み込み確認
$httpd -M |grep proxy
 proxy_module (shared)
 proxy_ajp_module (shared)
 proxy_balancer_module (shared)
 proxy_connect_module (shared)
 proxy_express_module (shared)
 proxy_fcgi_module (shared)
 proxy_fdpass_module (shared)
 proxy_ftp_module (shared)
 proxy_http_module (shared)
 proxy_scgi_module (shared)
 proxy_wstunnel_module (shared)

ProxyPass を記述して、Pathが /sample/ となっているのはAJPプロトコルを利用して8009ポートへ通信をする。

/etc/httpd/conf.modules.d/httpd-proxy.conf
ProxyPass /sample/ ajp://localhost:8009/sample/

以下で先ほど http://localhost:8080/sample/ で表示された内容が確認できればOK

$curl http://localhost/sample/

上記が表示できればローカルマシンからも http://[domain or IP]/sample/ でアクセスすれば表示される

スクリーンショット 2016-06-25 19.43.42.png

あとはサンプルを色々変えていけばOK

toshihirock
こちらは個人の意見で会社とは関係ありません。お約束です。
http://toshihirock.blogspot.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした