Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1271|回复: 0
打印 上一主题 下一主题

windows下面配置apache+https

[复制链接]

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
跳转到指定楼层
楼主
发表于 2018-3-13 18:21:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
https://www.cnblogs.com/huxiaoli/p/6274347.html
在Apache里配一个<VirtualHost *:6044>,然后针对这个6044设置https,https可反向代理映射到http地址,但http不可反向代理映射到https地址。
需要修改httpd.conf 、httpd-vhosts.conf两个文件
1、修改conf/httpd.conf 取消以下注释,使appache启动时调用ssl服务:
#LoadModule ssl_module modules/mod_ssl.so (去掉前面的‘#’号)#Include conf/extra/httpd-ssl.conf        (去掉前面的‘#’号)
2、生成证书
win+R:cmd进入命令行,进入apache安装目录的bin文件 cd C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin
设置OPENSSL_CONFIG配置,执行命令 set OPENSSL_CONF=..\conf\openssl.cnf
(a)生成服务端的key文件
  执行命令:openssl genrsa -out server.key 1024
        在bin目录中生成server.key文件
(b)生成签署申请
        执行命令:openssl req -new -out server.csr -key server.key
在bin目录中生成server.csr文件,在执行以上命令时会提示输入相关信息,其中 Common Name <eg,YOUR name>[] 需要与配置文件中的ServerName一致,否则apache启动时将会报错。     
[url=][/url]
Country Name<2 letter code>[AU] : cnState or Province Name <full name> [Some-State] : jangsuLocality Name<eg , city>[] : nanjingOraganization Name <eg,company> [Internet Widgits Pty Ltd]: epms.cwpOrganizational Unit Name <eg,section> [] epmsCommon Name<eg, YOUR name>[]:ServerNameEmail Address []: ....................................................................................................................A challenge password []: (可不输入)[url=][/url]

(c)生成CA的key文件
         执行命令:openssl genrsa -out ca.key 1024
         在目录bin下生成ca.key文件
(d) 生成CA自签署证书
   执行命令:openssl req -new -x509 -days 365 -key ca.key -out ca.crt
      在目录bin下生成ca.crt文件
(e)生成CA的服务器签署证书
执行命令:openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key
在这里报错了,按照网上的说法新建相应的文件夹,再执行一次就可以了。
在bin下新建demoCA文件夹                     =>bin/demoCA在demoCA下新建index.txt                 =>bin/demoCA/index.txt在demoCA下新建serial.txt,其内容为01,重命名删除.txt   =>bin/demoCA/serial在demoCA下新建newcert文件夹               =>sbin/demoCA/newcerts
 3、修改httpd-ssl.conf文件
(a)根据需要修改httpd-ssl.conf的默认端口号“443”,这里将所有的443修改为“6044”,同时修改ServerName。
<VirtualHost _default_:6044>          ServerName  ........................:6044
(b) 修改相关证书路径,把路径设置为conf下的key目录,把生成的证书放进这个目录
SSLCertificateFile    xxx/conf/key/server.crt    (服务器证书的位置) SSLCertificateKeyFile    xxx/conf/key/server.key (服务器私钥的位置) SSLCACertificateFile    xxx/key/conf/ca.crt      (CA根证书的位置,进行客户端验证时需要)
(c) 取消注释
#SSLVerifyClient require               (去掉前面的‘#’号,进行客户端验证时需要) #SSLVerifyDepth  1                     (去掉前面的‘#’号,把10改为1,进行客户端验证时需要)
(d) 选择性修改,如果在运行时报错,可修改SSLSessionCache再执行
修改前:
#SSLSessionCache         "dbm:C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/ssl_scache"SSLSessionCache        "shmcb:C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/ssl_scache(512000)"SSLSessionCacheTimeout  300
修改后:
SSLSessionCache         "dbm:C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/ssl_scache"#SSLSessionCache        "shmcb:C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/ssl_scache(512000)"SSLSessionCacheTimeout  300
4、重启apache,执行两个命令net stop Apache2.2net start Apache2.2,浏览器中输入https//..............:6044页面会提示 It works!
5、修改httpd-vhosts.conf 设置反向代理,重启apache,浏览器中输入https//..............:6044页面会跳转到相应的代理页面(注意DocumentRoot路径要存在)
[url=][/url]
NameVirtualHost *:6044## VirtualHost example:# Almost any Apache directive may go into a VirtualHost container.# The first VirtualHost section is used for all requests that do not# match a ServerName or ServerAlias in any <VirtualHost> block.#<VirtualHost *:6044>   DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/docs/"   ServerName ......:6044      SSLEngine on     SSLProxyEngine on   SSLCertificateFile "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/key/server.crt"   SSLCertificateKeyFile "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/key/server.key"   ProxyRequests Off       <Proxy *>  Order deny,allow  Allow from all  </Proxy>   ProxyPass / http://....../   ProxyPassReverse / http://....../</VirtualHost>[url=][/url]

6、假如遇到apache无法启动的时候,可以选我的电脑-》管理-》事件检查器-》应用程序日志,打开apache的错误报告,会有提示哪里出错了,一般都可以找到原因,
可以启动,但无法映射到对应页面,可以命令中输入httpd 会提示相应的错误。

没成功,可能是域名不对应的关系

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-5-6 06:05 , Processed in 0.058476 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表