Apache反向代理服务器的设置(第一层www.test2.com)
httpd.conf中的设置
...
#修改被访问端口号
Listen 8090
ServerName www.test2.com
...
#开启反向代理
ProxyPreserveHost On
#关闭代理
ProxyRequests Off
#使用ProxyPass指令激活反向代理
#请求中包含/index,请求将被转发给http://www.test3.com:8081/index/
ProxyPass /index http://www.test3.com:8081/index/
#和ProxyPass指令配合使用,使Apache调整HTTP重定向应答中Location, Content-Location, URI头里的URL
ProxyPassReverse /index http://www.test3.com:8081/index/
#所有请求转发给http://www.test3.com:8080/
ProxyPass / http://www.test3.com:8080/
ProxyPassReverse / http://www.test3.com:8080/
ProxyPass /todo http://www.test3.com:8080/todo/
ProxyPassReverse /todo http://www.test3.com:8080/todo/
...
关于ProxyPreserveHost的说明:
Enabling the Apache ProxyPreserveHost directive
The ProxyPreserveHost directive is used to instruct Apache mod_proxy, when acting as a reverse proxy, to preserve and retain the original Host: header from the client browser when constructing the proxied request to send to the target server.
The default setting for this configuration directive is Off, indicating to not preserve the Host: header and instead generate a Host: header based on the target server’s hostname.
Because this is often not what is wanted, you should add the ProxyPreserveHost On directive to the Apache HTTPD configuration, either in httpd.conf or related/equivalent configuration files.
squid反向代理服务器的设置(第二层www.test2.com)
关于squid的squid.conf设置
...
http_port www.test2.com:80 accel defaultsite=www.test2.com
...
cache_peer www.test2.com parent 8090 0 no-query originserver name=index
acl aclIndex urlpath_regex ^(/)?index(/)?
cache_peer_access index allow aclIndex
cache_peer www.test2.com parent 8090 0 no-query originserver name=todo
acl aclTodo urlpath_regex ^(/)?todo(/)?
cache_peer_access todo allow aclTodo
Apache反向代理服务器的设置(第三层www.test1.com)
关于https的ssl.conf设置
<Location /index>
ProxyPass http://www.test2.com:80/index
ProxyPassReverse http://www.test2.com:80/index
ProxyPassReverseCookieDomain www.test2.com www.test1.com
SetEnvIf Referer "https://www\.test1\.com/index/" allow_ref
SetEnvIf Referer "^$" allow_ref
order deny,allow
deny from all
allow from env=allow_ref
</Location>
<Location /todo>
ProxyPass http://www.test2.com:80/todo
ProxyPassReverse http://www.test2.com:80/todo
ProxyPassReverseCookieDomain www.test2.com www.test1.com
SetEnvIf Referer "https://www\.test1\.com/index/" allow_ref
SetEnvIf Referer "https://www\.test1\.com/todo/" allow_ref
SetEnvIf Referer "^$" allow_ref
order deny,allow
deny from all
allow from env=allow_ref
</Location>