apache的proxy功能由其proxy模块实现.加载模块有两种方式:静态和动态,现分别说明:
一 静态加载
静态加载,在编译apache时候编译进去,编译参数如下:
"./configure" \
"-prefix=/usr/local/apache3" \
"--enable-so" \
"--enable-rewrite" \
"--with-mpm=prefork" \
"--enable-proxy" \ (这个参数即是代理模块启用)
安装完成后查看模块列表
/usr/local/apache3/bin/httpd -l
显示
Compiled in modules:
core.c
mod_access.c
mod_auth.c
mod_include.c
mod_log_config.c
mod_env.c
mod_setenvif.c
mod_proxy.c
proxy_connect.c
proxy_ftp.c
proxy_http.c
prefork.c
http_core.c
.......
编辑配置文件 httpd.conf
在虚拟主机部分
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
ServerName www.a.org
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://192.168.0.115/
ProxyPa***everse / http://192.168.0.115/
</VirtualHost>
 
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
ServerName www.b.org
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://127.0.0.1:9000/
ProxyPa***everse / http://127.0.0.1:9000/
</VirtualHost>
 
二 动态加载
动态加载:编译进一个已经装好了的apache中(编译为dso模块)
已经装好的apache在 /usr/local/apache2
进入apache源码的模块目录进行编译
cd httpd-2.0.63/modules/proxy/
/usr/local/apache2/bin/apxs -c -i -a mod_proxy.c proxy_connect.c proxy_http.c proxy_util.c
从输出里面看到apache的modules目录下已经产生了mod_proxy.so,且已经在httpd.conf中激活了
cd /usr/local/apache2/conf/
ls ../modules/ 看到确实有mod_prxoy.so
编辑配置文件
vi httpd.conf
修改如下
加载模块
LoadModule proxy_module modules/mod_proxy.so (这句是编译激活时产生的)
LoadModule proxy_http_module modules/mod_proxy.so (这句是要手动添加的)
虚拟主机的部分加上
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
ServerName www.a.org
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://192.168.0.115/
ProxyPa***everse / http://192.168.0.115/
</VirtualHost>
 
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
ServerName www.b.org
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://127.0.0.1:9000/
ProxyPa***everse / http://127.0.0.1:9000/
</VirtualHost>
重启apache生效
 
注:
如果不加LoadModule proxy_http_module modules/mod_proxy.so,则浏览器页面打不开,页面显示
Forbidden
You don't have permission to access / on this server.
日志acess_log里面显示
192.168.0.28 - - [03/Jun/2009:16:16:27 +0800] "GET /?sessionId=4293567494722637330&rand=1244014624405&CONTEXT=0&page=com.othe
r.AjaxWhoWhatUpdate&xrand=1244016991554&wwRandId=1244014624405&wwBugId=2341&wwType=View HTTP/1.1" 403 315
或者
192.168.0.28 - - [03/Jun/2009:17:10:32 +0800] "GET / HTTP/1.1" 403 315
即403错误
日志error_log里面显示
[Wed Jun 03 17:08:46 2009] [warn] proxy: No protocol handler was valid for the URL /. If you are using a DSO version of mod_p
roxy, make sure the proxy submodules are included in the configuration using LoadModule.