ubuntu下apache+tomcat基于ajp协议的反代配置
环境是UBUNTU 最新版apache2安装的目录结构有变化网上很多文章都不适用了。
准备
如果你原程序有问题,先清理一下
- apt-get --purge remove apache2
- apt-get --purge remove apache2.2-common
- apt-get autoremove
- apt-get --purge remove apache-common
- apt-get --purge remove apache
- sudo find /etc -name "*apache*" -exec rm -rf {} /;
- sudo rm -rf /var/www
- dpkg -l |grep apache2|awk '{print $2}'|xargs dpkg -P #删除关联
安装
- apt-get install apache2
- service apache2 stop
配置
(1)
- a2enmod proxy proxy_ajp proxy_balancer proxy_connect proxy_ftp proxy_http
(2)
修改配置 sudo vim /etc/apache2/mods-enabled/proxy.conf
如果有内容设置则设置如下:
- <IfModule mod_proxy.c>
- #turning ProxyRequests on and allowing proxying from all may allow
- #spammers to use your proxy to send email.
- ProxyRequests Off
- <Proxy *>
- Require all granted
- </Proxy>
(3)
修改配置vim /etc/apache2/sites-enabled/000-default.conf
- <VirtualHost *:80>
- ServerName www.zhl123.cn
- ServerAdmin admin@zhl123.cn
- ProxyPass / ajp://127.0.0.1:8009/
- ProxyPassReverse / ajp://127.0.0.1:8009/
- </VirtualHost>
(4)安全相关的版本号隐藏
修改配置 vim /etc/apache2/conf-enabled/security.conf
ServerSignature Off
ServerTokens Prod
重启服务测试一下吧,你现在已经可以使用ajp代理至后端了