java 发表于 2018-3-13 18:21:06

windows下面配置apache+https

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启动时将会报错。   
https://common.cnblogs.com/images/copycode.gif
Country Name<2 letter code> : cnState or Province Name <full name> State] : jangsuLocality Name<eg , city>[] : nanjingOraganization Name <eg,company> : epms.cwpOrganizational Unit Name <eg,section> [] epmsCommon Name<eg, YOUR name>[]:ServerNameEmail Address []: ....................................................................................................................A challenge password []: (可不输入)https://common.cnblogs.com/images/copycode.gif

(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               (去掉前面的‘#’号,进行客户端验证时需要) #SSLVerifyDepth1                     (去掉前面的‘#’号,把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)"SSLSessionCacheTimeout300
修改后: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)"SSLSessionCacheTimeout300
4、重启apache,执行两个命令net stop Apache2.2和net start Apache2.2,浏览器中输入https//..............:6044页面会提示 It works!5、修改httpd-vhosts.conf 设置反向代理,重启apache,浏览器中输入https//..............:6044页面会跳转到相应的代理页面(注意DocumentRoot路径要存在)https://common.cnblogs.com/images/copycode.gif
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,allowAllow from all</Proxy>   ProxyPass / http://....../   ProxyPassReverse / http://....../</VirtualHost>https://common.cnblogs.com/images/copycode.gif

6、假如遇到apache无法启动的时候,可以选我的电脑-》管理-》事件检查器-》应用程序日志,打开apache的错误报告,会有提示哪里出错了,一般都可以找到原因, 可以启动,但无法映射到对应页面,可以命令中输入httpd 会提示相应的错误。
没成功,可能是域名不对应的关系
页: [1]
查看完整版本: windows下面配置apache+https