服务器配置openssl支持 https 访问

骑猪看日落 2021-12-16 01:13 370阅读 0赞

一、Windows + apache 下, 软件是xampp

  说明:部分参考(http://blog.sina.com.cn/s/blog_5d7dbbdd0101042n.html)

  首先要载入 mod_ssl 。

  1. 将证书生成的配置文件(http://tud.at/programm/openssl.cnf) 复制到 apache/bin/openssl.cnf

  2. cmd进入apache/bin目录(必须是 openssl.exe 所在目录)。 使用命令生成

    openssl req -config ./openssl.cnf -new-out server.csr

   ## 逐次填写信息

    openssl rsa -in privkey.pem -out server.key

    openssl x509 -in server.csr -out server.crt -req -signkey server.key

    openssl req -x509 -days 730 -key server.key -in server.csr > server.crt

   或,版本较新可以使用这个

set openssl_conf=.``/openssl``.cnf

openssl genrsa 4096 -des3 > server.key

openssl req -new -key server.key > server.csr

  1.   
  2.  或
  3.    set openssl_conf=./openssl.cnf
  4.    openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr
  5.    ## 加 -nodes 的作用: key 将不会用DES 加密字符加密, ————这在windows上可能非常重要,win上可能会有一个启动错误 SSLPassPhraseDialog builtin 。
  6.    ## 逐次填写内容. 设密码。    

  3.这当前进入的目录(***apache/bin)生成了几个文件, 将 server.key, server.crt 复制到

    apache/conf/ssl.crt/example.crt

    apache/conf/ssl.key/example.key

    ## 重命名,是在有多个虚拟主机时名字不重复

  4. 依照示例配置 http-ssl.conf.

    

  1. SSLEngine on

      ServerName example.com:443

  1. DocumentRoot "E:/www/example.com"

      #ServerAdmin webadmin@example.com

      #ErrorLog “logs/error.log”

      SSLCertificateFile “E:/mySoft/xampp/apache/conf/ssl.crt/example.crt”
      SSLCertificateKeyFile “E:/mySoft/xampp/apache/conf/ssl.key/example.key”

      
        CustomLog “logs/access.log” combined
      

      <Files ~”\.(cgi|shtml|phtml|php|htm|html?)$>
        SSLOptions +StdEnvVars
      

    

    其他参数和80端口一样就行。Files匹配 参数见说明 http://httpd.apache.org/docs/2.0/mod/mod_ssl.html#ssloptions

  可能遇到的错误:

  [warn] Init: (23.234.16.94:443) You configured HTTP(80) on the standard HTTPS(443) port!

  解决: SSLEngine on

  自动跳转到第一个vhost:

     之前加个 NameVirtualHost *:443   

  题外话:

    其实自己生成的证书没什么意义,仅供本地开发。 当然,有很多卖证书的网站,使用上面手动生成的 csr 文本内容生成 crt(sha1或sha2加密在这一步设定)。

  1.   VeriSign的过于昂贵,最便宜的要 2000一年。我申请了 startSsl.com 的免费版,当然它的基础付费版也才 $49一年,坑爹的是如果你要删除这个域名,需要付$24美元。最后
  2. 我搞了个 Comodo.com 的, $64.99/年,可以试用90天,很好。

  

  另外一个问题是, 如果你的运行系统是 windows xp sp2 以下, 并不支持sha2加密的,可以使用sha1加密,或者下载补丁 (官方补丁下载)

Linux记录暂无, 其实基本一样。

转载于:https://www.cnblogs.com/antarctican/p/4037945.html

发表评论

表情:
评论列表 (有 0 条评论,370人围观)

还没有评论,来说两句吧...

相关阅读