TW5.0---APACHE---SSL(window 环境 ) 实现过程一 先做好 APCHE-SSL 准备 1. 下载 apache_2.2.11-win32-x86-openssl-0.9.8i.msi 2 安装此 APACHE, 在进行下一步之前, 请确认 Apache 已经安装并可以正常工作. 并且 ssl 需要的文件在如下的位置 : [Apache 安装目录 ]/modules/mod_ssl.so [Apache 安装目录 ]/bin/openssl.exe, libeay32.dll, ssleay32.dll [Apache 安装目录 ]/conf/openssl.cnf 3. 通过命令行生成 SSL Cert & Key (1)<apache-install-dir>\bin> 这里是 E:\Apache2.2\bin (2) 生成证书请求文件 (.csr) 和私密文件 (privkey.pem) E:\Apache2.2\bin>openssl req -config..\conf\openssl.cnf -new -out server.csr WARNING: can't open config file: /usr/local/ssl/openssl.cnf Loading 'screen' into random state - done Generating a 1024 bit RSA private key..++++++...++++++ writing new private key to 'privkey.pem' Enter PEM pass phrase:(12345678) Verifying - Enter PEM pass phrase: (12345678) ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:CN State or Province Name (full name) [Some-State]:Beijing Locality Name (eg, city) []:Beijing Organization Name (eg, company) [Internet Widgits Pty Ltd]:Tongtech Organizational Unit Name (eg, section) []:TongWeb Common Name (eg, YOUR name) []:www.tongtech.com Email Address []:zhengyh@tongtech.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:changeit An optional company name []:tongtech E:\Apache2.2\bin> (3) 生成 server.key <apache-install-dir>\bin> openssl rsa -in privkey.pem -out server.key // 需提供生成 privkey.pem 的密码 ( 这里为上一步输入的密码 :12345678) (4) 生成 server.crt <apache-install-dir>\bin>openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650 ( 十年 ) 见列表 : E:\Apache2.2\bin>openssl x509 -in server.csr -out server.crt -req -signkey serve
r.key -days 3650 WARNING: can't open config file: /usr/local/ssl/openssl.cnf Loading 'screen' into random state - done Signature ok subject=/c=cn/st=beijing/l=beijing/o=tongtech/ou=tongweb/cn=www.tongtech.com/ema iladdress=zhengyh@tongtech.com Getting Private key 4. 将生成的 server.key 和 server.crt( 生成的 server.key 和 server.crt 存放在 <apache-install-dir>/bin/) 复制到 <apache-install-dir>/conf/ 5. 在 <apache-install-dir>/conf/httpd.conf 中, 打开注释 : LoadModule ssl_module modules/mod_ssl.so Include conf/extra/httpd-ssl.conf 6. 测试 SSL 是否成功 :<apache-install-dir>\bin>httpd.exe -D SSL -t, 如果显示 Syntax OK 表示安装成功 见下面列表 : E:\Apache2.2\bin>httpd.exe -D ssl -t httpd.exe: Could not reliably determine the server's fully qualified domain name, using 168.1.90.6 for ServerName Syntax OK 7. 重启 Apache; 8. 访问 https://168.1.90.6:444/, 页面返回 it works, 则 Apache 的 SSL 支持安装成功 说明 : Apache 缺省的 HTTPS 端口为 443 因为和 HTTPS 端口冲突, 需将 httpd-ssl.conf 中的 443 改成新的端口 444 修改项包括 Listen 444 ServerName localhost:444 二 实现 AJP 通道的重定向 1. 复制 AJP 插件 mod_jk.so( 从 http://tomcat.apache.org/download-connectors.cgi 下载 ) 至 E:\Apache2.2\modules 目录下 2. 在 E:\Apache2.2\conf 下创建 workers.properties 文件 ( 具体见附件 ) workers.properties 文件示例如下 : # 定义了一个负载平衡服务器, 名称与 mod_jk.conf 中对应 worker.list=loadbalancer # 节点 1 worker.work1.type=ajp13 worker.work1.host= 168.1.90.6 # TongWeb 的 IP worker.work1.port=7666 #AJP 的端口, 要和 TongWeb 的 AJP 端口对应 worker.work1.lbfactor=1 # 权重 worker.work1.socket_keepalive=1 worker.work1.socket_timeout=300 worker. work1.redirect= # 当 work1 不能访问时, 将请求转发到 work2 # 节点 2 含义同上 worker.work2.type=ajp13 worker.work2.host= 168.1.90.6 worker.work2.port=7667 worker.work2.lbfactor=1
worker.work2.socket_keepalive=1 worker.work2.socket_timeout=300 worker. work2.redirect= worker.loadbalancer.type=lb # 将两节点加入负载平衡服务器 worker.loadbalancer.balance_workers=work1,work2 # 保证会话亲和, 设为 true worker.loadbalancer.sticky_session=true # 需要转发,sticky_session_force 值必须为 false, 否则不转发. worker.loadbalancer.sticky_session_force=false worker.sslloadbalancer.type=lb worker.sslloadbalancer.balance_workers=work1,work2 worker.sslloadbalancer.sticky_session=false worker.sslloadbalancer.sticky_session_force=true worker.list=mystatus worker.mystatus.type=status worker.mystatus.read_only=true 3. 在 E:\Apache2.2\conf 下创建 mountfile.properties 文件, /*=loadbalancer 4. 在 E:\Apache2.2\conf 下创建 sslmountfile.properties 文件, /*=sslloadbalancer 5. 在 E:\Apache2.2\conf 下创建 mod_jk.conf 文件, # 加入 jk 模块 LoadModule jk_module modules/mod_jk.so # 加载 jk 配置文件 JkWorkersFile "e:/apache2.2/conf/workers.properties" #JkAutoAlias "e:/apache2.2/htdocs/examples" #JkUnMount /*.jpg loadbalancer #JkUnMount /*.gif loadbalancer # 加载 jk 日志文件 JkLogFile "e:/apache2.2/logs/mod_jk.log" # 设置 jk 日志解别 JkLogLevel error # 设置 jk 日志格式 JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories JkRequestLogFormat "%w %V %T" # 转发到后台的请求 URI, 定义了一个负载平衡服务器 loadbalancer JkMount /* loadbalancer
#apache 的状态监控页面 JkMount /tongstatus mystatus 6. 在 E:\Apache2.2\conf\httpd.conf 尾部中增加如下配置 : Include conf/mod_jk.conf JkMountFile conf/mountfile.properties // 所有 HTTP 请求由负载均衡器 loadbalancer 转发 7. 在 E:\Apache2.2\conf\extra\httpd-ssl.conf 中配置如下 : JkMountFile conf/sslmountfile.properties // 所有 HTTPS 请求由负载均衡器 sslloadbalancer 转发 </VirtualHost> 8. 重启 apache 三 将 Apache2.2 作为 Proxy Server 的使用步骤 1 配置基于 HTTP 的 proxy 转发 (1) 将 E:\Apache2.2\conf\httpd.conf 中 LoadModule 信息去掉注释 : LoadModule proxy_connect_module modules/mod_proxy_connect.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_module modules/mod_proxy.so (2) 在 E:\Apache2.2\conf\httpd.conf 的尾部添加如下内容, 其中 168.1.90.6 是应用服务器, 7001 为 HTTP 监听端口 dbpool 为要代理的应用前缀 ProxyPass /dbpool http://168.1.90.6:7001/dbpool ProxyPassReverse /dbpool http://l68.1.90.6:7001/dbpool (3) 重启 Apache; (4) 通过 "http://168.1.90.6/dbpool (ApacheAddress 是 Apache 的 IP 地址, Port 是 Apache 的 HTTP 监听端口 80)" 成功访问 dbpool 应用 2 配置基于 HTTPS 的 Proxy 转发 (1) 将 E:\Apache2.2\conf httpd.conf 中 LoadModule 信息去掉注释 :
LoadModule proxy_connect_module modules/mod_proxy_connect.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_module modules/mod_proxy.so (2) 在 E:\Apache2.2\conf\extra\httpd-ssl.conf 中添加如下内容 ProxyPass /dbpool https://168.1.90.6:9066/dbpool // 其中 :168.1.90.6 是 TongWeb5.0 HTTPS 通道的监听地址,9066 为 HTTPS 通道的监听端口 </VirtualHost> (3) 重启 Apache; (4) 通过 "https://168.1.90.6:444/dbpool (168.1.90.6 是生成证书时设置的域名,444 是 Apache 的 HTTPS 端口 )" 成功访问应用