一、apache2.4代理转发tomcat7
通过http_proxy做tomcat的端口转发:
描述:将远程服务器映射到本地服务器的URL空间
语法:ProxyPass [路径] !|url [键=值键=值 ...]] [nocanon]
上下文:server config, virtual host, directory
状态:扩展
模块:mod_proxy
配置httpd.conf:
#保证以下模块加载
LoadModuleproxy_module modules/mod_proxy.so
LoadModuleproxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
在httpd.conf中开启
配置ProxyPass
进入: C:\Apache24\conf\extra\httpd-vhosts.conf 配置
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName www.test.com
ServerAlias www.test.com
ErrorLog "logs/www.zfsyjy.com-error.log"
CustomLog "logs/www.zfsyjy.com.log" common
#ProxyPass /slsc http://www.zfsyjy.com:9091/slsc
#ProxyPassReverse /slsc http://www.zfsyjy.com:9091/slsc
ProxyPass / http://127.0.0.1:8081/
ProxyPassReverse / http://127.0.0.1:8081/
</VirtualHost>
权限
可将Require all denied修改为Require all granted允许外部访问,或修改为Require host localhost只允许本机访问,或修改为Require ip x.x.x.x 允许指定的IP访问。
如将mantisbt的doc可在本地访问,可修改doc目录下的.htaccess文件。
1)如果是本机安装,可将Require all denied修改为Require ip 127.0.0.1
2)如果是安装在docker下,可将Require all denied修改为Require ip 172.17.0.1
具体看日志中报错的client ip 地址。
2、如果放开指定目录的访问权限,也可在virtualhost的directory配置中明确设定Require all granted。
<Directory /var/www/html>
Options -Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
多个反向代理:
ProxyRequests off
###默认跳转地址
RewriteEngine On
RewriteCond %{HTTP_HOST}^ www.test.com
RewriteRule ^/$ http://www.test.com/abc
<Proxy /test>
Require all granted
</Proxy>
ProxyPass /test http://127.0.0.1:9099/test
ProxyPassReverse /test http://127.0.0.1:9099/test
<Proxy /test2>
Require all granted
</Proxy>
ProxyPass /test2 http://127.0.0.1:9098/test2
ProxyPassReverse /test2 http://127.0.0.1:9098/test2