zoukankan      html  css  js  c++  java
  • windows配置openssl

    下载openssl并安装,下载地址:http://slproweb.com/products/Win32OpenSSL.html

    假设安装路径为C:"Program Files"OpenSSL-Win64inopenssl.exe

    如果没有加入系统环境变量,下面的命令里的openssl要换成安装路径的值

    一、生成秘钥

    openssl genrsa 1024 > server.key

    这是用128位rsa算法生成密钥,得到server.key文件 > 是输出文件的标识符

    二、生成未签署的server.csr 

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

    这是用步骤1的密钥生成证书请求文件server.csr, 这一步会有很多参数,需要一一输入


    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):SW_TECH公司名称
    Organizational Unit Name (eg, section) []:SW_TECH组织名称
    Common Name (eg, YOUR name) []:kedou.com申请证书的域名
    Email Address []:admin@admin.com 管理员邮箱
    Please enter the following 'extra' attributes
    to be sent with your certificate request
    A challenge password []: 交换密钥
    An optional company name []:  注:Common Name必须和httpd.conf中server name必须一致,否则apache不能启动 (启动apache时错误提示为:RSA server certificate CommonName (CN) `Kedou' does NOT match server name!? )


     四、签署服务器证书文件server.crt
    openssl req -x509 -days 365 -key server.key -in server.csr > server.crt 
    说明:这是用步骤1,2的的密钥和证书请求生成证书server.crt,-days参数指明证书有效期,单位为天,x509表示生成的为X.509证书。


    五、这一步可选,配置apache的httpd.conf.
    在conf目录下的httpd_ssl.conf文件是关于ssl的配置,是httpd.conf的一部分,在 httpd.conf中找到给文件的引用,移除对应的注释
    Include conf/extra/httpd-ssl.conf
    LoadModule ssl_module modules/mod_ssl.so

    修改httpd-ssl.conf文件 并配置
    SSLCertificateFile "D:/phpStudy/Apache/conf/ssl/server.crt" (具体的服务器地址)
    SSLCertificateKeyFile "D:/phpStudy/Apache/conf/ssl/server.key" (具体的服务器地址)
    CustomLog "D:/PHPStudy/Apache/logs/ssl_request.log"
    "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x "%r" %b"

    配置
    <VirtualHost _default_:443>

    # General setup for the virtual host
    DocumentRoot "D:/PHPStudy/WWW/" (域名带访问的目录)
    ServerName www.rgweb.com:443 (域名)
    ServerAdmin admin@admin.com (管理员邮箱)
    ErrorLog "D:/PHPStudy/Apache/logs/ssl_error.log.txt" (写入日志)
    TransferLog "D:/PHPStudy/Apache/logs/ssl_trans_error.log.txt" (写入日志)

    至此重启apache 
    浏览器输入 https 加你配置的域名

    注:错误:WARNING: can't open config file: /apache24/conf/openssl.cnf

    解决:将openssl_conf 放入环境变量  set openssl_conf=../conf/openssl.cnf

    错 :Unable to write ‘random state 

    解决:是因为没有用管理员进入cmd,使用管理员身份进入cmd 就解决了

    六、用flask等程序的话直接调用生成证书即可

    flask使用证书,如果报ssl错误,需注意证书在代码里的位置是否有调换,

    'server.crt','server.key'这两个证书出现在代码里的位置不可以调换
    app.run('0.0.0.0', debug=True, port=5000, ssl_context=('server.crt','server.key'))



  • 相关阅读:
    git ignore 添加忽略文件
    python| 闭包函数及装饰器
    python | DRF 框架知识总览
    python | CHROME底层原理和HTTP协议
    python| css 背景图片虚化效果
    python | js 图片与base64互相转换
    python | Linux各目录及每个目录的详细介绍
    python | 解决Django+Vue前后端分离的跨域问题及关闭csrf验证
    python | Nginx负载均衡策略
    python | Linux 搭建Nginx+uWSGI+Django环境
  • 原文地址:https://www.cnblogs.com/slqt/p/10601227.html
Copyright © 2011-2022 走看看