zoukankan      html  css  js  c++  java
  • nginx配置openssl证书

    引用出处: https://blog.csdn.net/liuchunming033/article/details/48470575

    证书生成基本步骤: 生成私钥(.key)-->生成证书请求(.csr)-->用CA根证书签名得到证书(.crt)

    CA根证书的生成步骤

    生成CA私钥(.key)-->生成CA证书请求(.csr)-->自签名得到根证书(.crt)(CA给自已颁发的证书)。

    [plain] view plain copy
     
    1. # Generate CA private key   
    2. openssl genrsa -out ca.key 2048   
    3. # Generate CSR   
    4. openssl req -new -key ca.key -out ca.csr  
    5. # Generate Self Signed certificate(CA 根证书)  
    6. openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt  

    在实际的软件开发工作中,往往服务器就采用这种自签名的方式,因为毕竟找第三方签名机构是要给钱的,也是需要花时间的。

    用户证书的生成步骤

    生成私钥(.key)-->生成证书请求(.csr)-->用CA根证书签名得到证书(.crt)

    下面生成服务端和客户端两个证书,用于双向认证

    服务器端用户证书:

    [html] view plain copy
     
    1. # private key  
    2. $openssl genrsa -des3 -out server.key 1024   
    3. # generate csr  
    4. $openssl req -new -key server.key -out server.csr  
    5. # generate certificate  
    6. $openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key   

    如果签名失败,需要根据出错信息先配置openssl.conf文件, 并创建几个文件

    客户端用户证书:

    [plain] view plain copy
     
    1. $openssl genrsa -des3 -out client.key 1024   
    2. $openssl req -new -key client.key -out client.csr  
    3. $openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key  

    生成pem格式证书 
    有时需要用到pem格式的证书,可以用以下方式合并证书文件(crt)和私钥文件(key)来生成 
    $cat client.crt client.key> client.pem 
    $cat server.crt server.key > server.pem
    结果:
    服务端证书:ca.crt, server.key, server.crt, server.pem
    客户端证书:ca.crt, client.key, client.crt, client.pem

    nginx配置

    http{
    
    #....
    
        server {
            listen 80;
            listen 443 ssl;
            ssl_certificate /root/server.crt;
            ssl_certificate_key /root/server.key;
        }
    }

    启动nginx时会让输入PEM密码,

    客户端使用https协议发起请求 curl -k https://xxxx

  • 相关阅读:
    Windows Azure Cloud Service (14) 使用Windows Azure诊断收集日志记录数据
    Windows Azure Cloud Service (13) 用Visual Studio 2010 将应用程序部署到Windows Azure平台
    Windows Azure Cloud Service (15) 多个VM Instance场景下如何处理ASP.NET Session
    Windows Azure Storage (5) Windows Azure Drive
    Windows Azure Storage (7) 使用工具管理Windows Azure Storage
    SQL Azure(二) SQL Azure vs SQL Server
    webbrowser的自动提交
    提取视频的背景声音的软件
    Listview列排序的bug原因
    两个奇怪的问题
  • 原文地址:https://www.cnblogs.com/yszzu/p/9223977.html
Copyright © 2011-2022 走看看