httpd通过ajp协议反向代理tomcat

外网服务器上启动tomcat。

[root@VM_0_12_centos bin]# ./startup.sh 
Using CATALINA_BASE: /root/tomcat/apache-tomcat-7.0.72
Using CATALINA_HOME: /root/tomcat/apache-tomcat-7.0.72
Using CATALINA_TMPDIR: /root/tomcat/apache-tomcat-7.0.72/temp
Using JRE_HOME: /usr
Using CLASSPATH: /root/tomcat/apache-tomcat-7.0.72/bin/bootstrap.jar:/root/tomcat/apache-tomcat-7.0.72/bin/tomcat-juli.jar
Tomcat started.

  

[root@VM_0_12_centos bin]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:8009            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN     
[root@VM_0_12_centos bin]# curl -I 127.0.0.1:8080
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=ISO-8859-1
Transfer-Encoding: chunked
Date: Fri, 02 Aug 2019 01:23:38 GMT

服务器本地可访问,外网访问不了

 

tomcat 8080 端口不对外开发,ajp端口对外开放。

本地配置httpd 反向代理服务器上的tomcat。

将 httpd.conf 配置文件中 

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

两项开启。

Include conf/vhosts.conf 注释去掉

vhosts.conf 文件中写入

<VirtualHost *:80> 
         ServerAdmin aaa@qq.com
         ServerName test.com 
         ServerAlias test.com 
         ProxyPass / ajp://服务器IP:8009/
         ProxyPassReverse / ajp://服务器IP:8009/
         ErrorLog "logs/ajptest-error.log" 
         CustomLog "logs/ajptest-access.log" common
</VirtualHost>

 

重新启动httpd服务。

hosts文件中增加一行 127.0.0.1  test.com

本地访问 test.com

 

posted @ 2019-08-01 17:10  depycode  阅读(1083)  评论(0编辑  收藏  举报