数码之家

 找回密码
 立即注册
搜索
查看: 234|回复: 0

Windows Apache2.4环境下配置支持HTTPS协议的SSL加密证书

[复制链接]
发表于 2023-10-29 19:31:46 | 显示全部楼层 |阅读模式 IP属地:福建厦门

爱科技、爱创意、爱折腾、爱极致,我们都是技术控

您需要 登录 才可以下载或查看,没有账号?立即注册

x
1.准备工作
1)在设置Apache + SSL之前, 需要做:
安装Apache, 下载安装Apache时请下载带有SSL版本的Apache安装程序.
并且ssl需要的文件在如下的位置:
    [Apache安装目录]/modules/ mod_ssl.so
    [Apache安装目录]/bin/ openssl.exe, libeay32.dll, ssleay32.dll, openssl.cnf
    [Apache安装目录]/conf/ openssl.cnf
创建SSL证书(注意,有的集成环境里面自带了openssl,但是bin目录下没有openssl.cnf,需要将conf下的openssl.cnf拷贝一份到bin目录下,但总体原理一样)
2)在windows环境下需先设置Openssl环境变量:
执行命令  set OPENSSL_CONF=..\conf\openssl.cnf

打开CMD,进入到Apache安装目录下的bin目录下:
1062096-20170123102708831-285417619.png
步骤一:执行命令 openssl genrsa 1024 >server.key
说明:RSA密钥对的默认长度是1024,取值是2的整数次方,并且密钥长度约长,安全性相对会高点。

完成密钥server.key生产完毕后进行步骤二操作。

步骤二:生产为签署的server.csr,继续在bin目录下执行命令:
openssl req -new -config openssl.cnf -key server.key >server.csr
说明:如果不加-config .openssl.cnf参数的话,常会报Unable to load config info from .../ssl/openssl.cnf

之后就会要求输入一系列的参数:
    Country Name (2 letter code) [AU]:CN ISO 国家代码(只支持两位字符)
    State or Province Name (full name) [Some-State]:ZJ 所在省份
    Locality Name (eg, city) []:HZ 所在城市
    Organization Name (eg, company): yiban公司名称
    Organizational Unit Name (eg, section) []:yiban 组织名称
    Common Name (eg, YOUR name) []: localhost:80申请证书的域名(建议和httpd.conf中serverName必须一致)
    Email Address []:admin@admin.com 管理员邮箱
    Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: 1234交换密钥
An optional company name []:CD
注:Common Name建议和httpd.conf中serverName必须一致,否则有可能导致apache不能启动
(启动 apache 时错误提示为:server RSA certificate CommonName (CN) `Kedou' does NOT match server name!?)完成签署的server.csr配置。
步骤三:
签署服务器证书文件 server.crt
    在 bin/目录下执行命令:   
openssl req -x509 -days 5000 -config openssl.cnf -key server.key -in server.csr >server.crt
说明:这是用步骤 1,2 的的密钥和证书请求生成证书 server.crt,-days 参数 指明证书有效期,单位为天,x509 表示生成的为 X.509 证书。
步骤四:
在bin 目录下,找到server.crt、server.csr、server.key三个文件,将此三个文件剪切到Apache的conf目录下。
步骤五:
配置 httpd.conf. 在Apache的conf\extra目录下的 httpd_ssl.conf 文件是关于 ssl 的配置,是httpd.conf的一部分。
在httpd.conf 中添加下列两行(有的话把文件前面的注释“#”符号去掉):
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf      
步骤六:
  (注意:相同部分被省略掉)
在conf\extra目录下,编辑 httpd_ssl.conf


  1. Listen 443

  2. SSLPassPhraseDialog  builtin

  3. SSLSessionCache   "dbm:c:/Apache24/logs/ssl_scache"

  4. #SSLSessionCache  "shmcb:c:/Apache24/logs/ssl_scache(512000)"

  5. (以上2种请自行监测,如有一种导致服务器启动不了,就换成另一种)

  6. SSLSessionCacheTimeout  300

  7. <VirtualHost www.my.com:443>

  8.     #DocumentRoot "D:/wamp/bin/apache/apache2.4.9/htdocs"

  9.     DocumentRoot "C:/wamp/www/hxq"

  10.     ServerName  www.my.com:443

  11.     ServerAlias my.com:443

  12.     ServerAdmin webmaster@chinancce.com

  13.     DirectoryIndex index.html index.htm index.php default.php app.php u.php

  14.     ErrorLog logs/example_error.log

  15.     CustomLog logs/example_access.log \

  16.     "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x "%r" %b"

  17.     SSLEngine On

  18.     SSLCertificateFile "C:/wamp/bin/apache/apache2.4.9/conf/server.crt"

  19.     SSLCertificateKeyFile "C:/wamp/bin/apache/apache2.4.9/conf/server.key"

  20.     #SSLCertificateChainFile "C:/upupw/Apache2/conf/1_root_bundle.crt"

  21. <FilesMatch "\.(shtml|phtml|php)$">

  22.     SSLOptions +StdEnvVars

  23. </FilesMatch>

  24.     BrowserMatch "MSIE [2-5]" \

  25.     nokeepalive ssl-unclean-shutdown \

  26.     downgrade-1.0 force-response-1.0

  27. <Directory "C:/wamp/www/hxq">

  28.     Options FollowSymLinks

  29.     AllowOverride All

  30.     Order allow,deny

  31.     Allow from all

  32. </Directory>

  33. </VirtualHost>
复制代码

以上最容易出问题的地方是http_ssl.conf中的日志等路径问题,建议按照物理路径进行设置
步骤七:
调试运行Apache,对于Apache。如果是集成环境如xampp,wampserver,或者phpstudy启动Apache Server,可能我们不知道我们的服务器出现了什么问题,建议查看 Apache/logs下的日志,在此基础上,配合cmd命令行在bin目录下运行httpd命令,如果不报错,说明服务器运行没问题,否则根据提示再做修改
2.测试运行
重启apahce服务,访问https://www.my.com/,完工!
1062096-20170123103011566-2110286075.png
===========出现错误汇集==========

1、"Syntax error on line 80 of c:/apache/conf/extra/httpd-ssl.conf:ErrorLog takes one argument,The filename of the error log"或者"Syntax error on line 99 of c:/apache/conf/extra/httpd-ssl.conf:SSLCertificateFile takes one argument,SSL Server Certificate file ('/path/to/file' -PEM or DER encoded)"
解决方法:文件路径加双引号
2、"Syntax error on line 76 of C:/apache/conf/extra/httpd-ssl.conf:SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?)."
解决办法:
打开httpd.conf,
找到LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
把前面的注释去掉。






来自:欢乐豆123





APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2024-4-28 17:54 , Processed in 0.140400 second(s), 16 queries , Redis On.

Powered by Discuz!

© 2006-2023 smzj.net

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