标签:apache apache反向代理 windwosapache反向代理 windows反向代理 apache+tomcat集群 session问题
测试环境:Apache反代做为前端反向代理,后端任意,此处我用做windwos,其实linux与windwos配置原理都一样,只是根据公司需求来做。
需求: 要求基于ssl访问,
301域名跳转,
session sticky方式来接收请求,
有故障隔离的作用,以至于在其中一台上线时可以把用户请求转发到另一台。
Apache(windows安装包)下载路径
http://www.apachelounge.com/download/
64位下载
http://download.microsoft.com/download/9/E/1/9E1FA77A-9E95-4F3D-8BE1-4D2D0C947BA2/enu_INREL/vcredistd14x64/vc_redist.x64.exe
32位下载
http://download.microsoft.com/download/9/E/1/9E1FA77A-9E95-4F3D-8BE1-4D2D0C947BA2/enu_INREL/vcredistd14x86/vc_redist.x86.exe
上传资源至服务器e:/tmp
安装vc_redist工具:
点安装-->
4.1减压到E:/Apache24
4.2修改配置文件路径conf/httpd.conf
4.3找到默认218行把# ServerName www.example.com:80
换成ServerName www.wyy.com:80
4.4测试正常启动
4.5加入系统服务
4.6启动程序ApacheMonitor.exe -->start
4.7查看Apache是否正常访问
黏贴性session的问题解决
5.1修改配置文件conf/http.conf
取消以下模块的注释 #
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModulelbmethod_byrequests_modulemodules/mod_lbmethod_byrequests.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule headers_module modules/mod_headers.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
5.2再末尾加入以下代码:
# AJP13 Proxy
<IfModule mod_proxy.c>
<IfModule mod_proxy_ajp.c>
Include "conf/extra/httpd-ajp.conf"
</IfModule>
</IfModule>
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Allow from all
</Location>
5.3在conf/extra下创建httpd-ajp.conf
写入以下代码:
<Proxy *>
Require all granted
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
</Proxy>
ProxyPass /test balancer://rqbao_cluster/ stickysession=ROUTEID
ProxyRequests Off
<Proxy balancer://rqbao_cluster>
BalancerMember ajp://10.1.1.252:8009 route=tomcat1 ping=3
BalancerMember ajp://10.1.1.253:9009 route=tomcat2 ping=3
</Proxy>
6.1打开 httpd.conf 文件开启ssl功能
Include conf/extra/httpd-ssl.conf
6.2打开extra/httpd-ssl.conf文件修改文件内容路径
6.3默认125行改为自己的域名或者ip地址
ServerName www.wyy.com:443
6.4默认144、154、165
改为:
SSLCertificateFile "e:/Apache24/conf/webCert.cer"
SSLCertificateKeyFile "e:/Apache24/conf/server.key"
SSLCertificateChainFile "e:/Apache24/conf/ruiqianbao.pem"
6.5把e:/tmp下的webCert.cer、server.key、ruiqianbao.pem这3个文件放到Apache下的conf目录里
测试配置文件
最后restart Apache 服务
完成!
开启LoadModule rewrite_module modules/mod_rewrite.so
根据要跳转的域名加入以下代码:
##############301域名跳转#########
RewriteEngine On
RewriteCond %{http_host} bbs.wyy.com [NC]
RewriteRule ^(.*)$ https://www.wyy.com [L,R=301]
RewriteEngine On
RewriteCond %{http_host} blog.wyy.com [NC]
RewriteRule ^(.*)$ http://www.wyy.com [L,R=301]
RewriteEngine On
RewriteCond %{http_host} www.wyy.com.net [NC]
RewriteRule ^(.*)$ http://www.wyy.com [L,R=301]
7.1在Tomcat根目录创建test.jsp测试文件
加入以下代码:
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*" %>
<html><head><title>Cluster Test</title></head>
<body>
<%
//HttpSession session = request.getSession(true);
System.out.println(session.getId());
out.println("<br> SESSION ID:" + session.getId()+"<br>");
// 如果有新的请求,则添加session属性
String name = request.getParameter("name");
if (name != null && name.length() > 0) {
String value = request.getParameter("value");
session.setAttribute(name, value);
}
out.print("<b>Session List:</b>");
Enumeration<String> names = session.getAttributeNames();
while (names.hasMoreElements()) {
String sname = names.nextElement();
String value = session.getAttribute(sname).toString();
out.println( sname + " = " + value+"<br>");
System.out.println( sname + " = " + value);
}
%>
<form action="testCluster.jsp" method="post">
名称:<input type=text size=20 name="name">
<br>
值:<input type=text size=20 name="value">
<br>
<input type=submit value="提交">
</form>
</body>
</html>
7.2 http://10.1.1.252/balancer-manager监控页面
本文出自 “好大的刀” 博客,谢绝转载!
标签:apache apache反向代理 windwosapache反向代理 windows反向代理 apache+tomcat集群 session问题
原文地址:http://53cto.blog.51cto.com/9899631/1696745