吾知网

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

windows下面配置apache+https

[复制链接]
跳转到指定楼层
楼主
发表于 2018-10-21 20:26:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

在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启动时将会报错。        

复制代码
Country Name<2 letter code>[AU] : cn
State or Province Name <full name> [Some-State] : jangsu
Locality Name<eg , city>[] : nanjing
Oraganization Name <eg,company> [Internet Widgits Pty Ltd]: epms.cwp
Organizational Unit Name <eg,section> [] epms
Common Name<eg, YOUR name>[]:ServerName
Email Address []: ..................................
..................................................................................
A challenge password []: (可不输入)
复制代码

 (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路径要存在)

复制代码
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     
  <roxy *>
  Order deny,allow
  Allow from all
  </Proxy>
   ProxyPass / http://....../
   ProxyPassReverse / http://....../
</VirtualHost>
复制代码

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

可以启动,但无法映射到对应页面,可以命令中输入httpd 会提示相应的错误。

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

本版积分规则

小黑屋|手机版|Archiver|吾知网 ( 粤ICP备13013563号-1 )

GMT+8, 2024-4-19 18:04 , Processed in 1.093750 second(s), 8 queries , Memcache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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