hopeless-dream

导航

AJP与http协议反向代理

安装httpd

https://www.cnblogs.com/zh-dream/p/14832154.html

安装tomcat

https://www.cnblogs.com/zh-dream/p/13511041.html

 地址规划

apache地址10.0.0.10    tomcat地址10.0.0.20

apache开启代理模块

# vim conf/httpd.conf

LoadModule proxy_module modules/mod_proxy.so       # 反向代理主模块
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so       # AJP协议代理模块

  LoadModule proxy_http_module modules/mod_proxy_http.so # http协议代理模块

配置http协议的反向代理

配置apache

#禁止所有非法域名
<VirtualHost *:80>
        ServerName 10.0.0.10
        <Location />
                Order Allow,Deny
                Deny from all
        </Location>
</VirtualHost>

#允许域名访问
<VirtualHost *:80>                        # 监听在本机的80端口
        DocumentRoot htdocs

        ServerName web1.test.com      # 主机名
        ServerAlias web1.test.com
        <Directory "test">
            Options Indexes FollowSymLinks
            AllowOverride all
            Order allow,deny
            Allow from all
        </Directory>

        ProxyVia on                        # 和nginx的X-via差不多 指明由谁反向代理请求的
        ProxyRequests Off           # 显式关闭正向代理      
        ProxyPreserveHost On               # 将请求向后端转发时,是否支持在后端主机上基于主机名的虚拟主机 httpd自动支持
        <Proxy *>
             Require all granted          # 允许所有人访问
        </Proxy>
         ProxyPass /  http://10.0.0.20:8080/   # 把对于/下的所有内容的请求反向代理至后面的主机
         ProxyPassReverse /  http://10.0.0.20:8080/
        <Location />
            Require all granted
        </Location>
</VirtualHost>

重载apache

[root@localhost http-2.4.48]# httpd -t
Syntax OK
[root@localhost http-2.4.48]# apachectl -k graceful

tomcat配置访问路径

$ vim conf/server.xml 
     <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

      <Context docbase="app" path="/app" reloadable="true" />

访问测试

 

 

 

 

 

 ajp协议配置反向代理

[root@localhost http-2.4.48]# vim conf/extra/httpd-vhosts.conf
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
#禁止所有非法域名
<VirtualHost *:80>
        ServerName 10.0.0.10
        <Location />
                Order Allow,Deny
                Deny from all
        </Location>
</VirtualHost>

#允许域名访问
<VirtualHost *:80>                        # 监听在本机的80端口
        DocumentRoot htdocs

        ServerName web1.test.com
        ServerAlias web1.test.com
        <Directory "test">
            Options Indexes FollowSymLinks
            AllowOverride all
            Order allow,deny
            Allow from all
        </Directory>

        ProxyVia on
        ProxyRequests Off
        ProxyPreserveHost On
        <Proxy *>
             Require all granted
        </Proxy>
         ProxyPass / ajp://10.0.0.20:8009/
         ProxyPassReverse / ajp://10.0.0.20:8009/
        <Location />
            Require all granted
        </Location>
</VirtualHost>
"conf/extra/httpd-vhosts.conf" 78L, 2337C written                                                                                         
[root@localhost http-2.4.48]# httpd -t
Syntax OK
[root@localhost http-2.4.48]# systemctl restart httpd

开启apache的status

1、修改主配置文件,开启status模块(如果未安装需要重新编译apache,或者使用modprobe导入下载模块)

LoadModule status_module modules/mod_status.so

2、修改虚拟主机配置文件


[root@localhost http-2.4.48]# cat conf/extra/httpd-vhosts.conf


#禁止所有非法域名
<VirtualHost *:80> ServerName 10.0.0.10 <Location /> Order Allow,Deny Deny from all </Location> </VirtualHost> #允许域名访问 <VirtualHost *:80> # 监听在本机的80端口 DocumentRoot htdocs ServerName web1.test.com ServerAlias web1.test.com <Directory "test"> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all </Directory> ProxyVia on ProxyRequests Off ProxyPreserveHost On <Proxy *> Require all granted </Proxy> ProxyPass /server-status ! ProxyPass / ajp://10.0.0.20:8009/ ProxyPassReverse / ajp://10.0.0.20:8009/ <Location /> Require all granted </Location> <Location /server-status> SetHandler server-status Order Deny,Allow Allow from all </Location> </VirtualHost>

重启apache并访问测试

[root@localhost http-2.4.48]# httpd -t
Syntax OK
[root@localhost http-2.4.48]# systemctl restart httpd

 

posted on 2021-06-08 11:37  hopeless-dream  阅读(252)  评论(0编辑  收藏  举报