• Nginx SSL配置


    一、SSL 原理

    ① 客户端( 浏览器 )发送一个 https 请求给服务器
    ② 服务器要有一套证书,其实就是公钥和私钥,这套证书可以自己生成,也可以向组织申请,服务器会把公钥传输给客户端
    ③ 客户端收到公钥后,会验证其是否合法有效,无效会有警告提醒,有效则会生成一串随机数,并用收到的公钥加密,然后把加密后的随机字符串传输给服务器
    ④ 服务器收到加密随机字符串后,先用私钥解密来获取到这一串随机字符串,再用这串随机字符串加密要传输的数据,然后把加密后的数据传给客户端
    ⑤ 客户端收到数据后, 再用自己的私钥也就是那个随机字符串进行解密,最终得到想要的数据

    二、Nginx SSL 配置

    1. 先生成一套证书( 这里我们先自己生成证书来做实验,在实际中应该向合法机构购买证书 )

    [root@localhost ~]$ cd /usr/local/nginx/conf/
    [root@localhost conf]$ openssl genrsa -des3 -out tmp.key 2048                   # 生成私钥文件(tmp.key),会让你设置私钥文件的密码
    [root@localhost conf]$ openssl rsa -in tmp.key -out ssl.key && rm -f tmp.key    # 转换私钥文件(ssl.key),把密码取消掉,否则客户端用https访问时需要输入密码
    [root@localhost conf]$ openssl req -new -key ssl.key -out ssl.csr               # 生成一个证书请求文件(ssl.csr),需要用到这个请求文件与私钥文件结合来生成公钥文件,会让你填一些信息,可以随便填
    [root@localhost conf]$ openssl x509 -req -days 365 -in ssl.csr -signkey ssl.key -out ssl.crt && rm -f ssl.csr   # 根据证书请求文件来生成公钥(ssl.crt)

    2. Nginx 配置 SSL

    [root@localhost ~]$ cat /usr/local/nginx/conf/vhost/ssl.conf 
    server {
        listen 443;                   # https监听443端口
        server_name www.test.com;
        index index.html index.htm index.php;    
        root /data/www;
        
        ssl on;                                 # 开启SSL
        ssl_certificate ssl.crt;                # 指定公钥文件
        ssl_certificate_key ssl.key;            # 指定私钥文件
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;    # 指定支持的SSL协议版本
    }
    [root@localhost ~]$ /usr/local/nginx/sbin/nginx -t                  
    [root@localhost ~]$ /etc/init.d/nginx restart         # 注意配置https要重启,不是重载

    3. 客户端使用 https 方式访问

           

  • 相关阅读:
    QTimer::singleShot
    Qt 建立带有子项目的工程
    Qt GlobalColor及其显示
    QT自定义图形项中的boundingRect()和shape()函数的理解
    QT setZValue() 函数
    C++中explicit的作用及用法
    QT中foreach的使用
    QT代码封装成dll和lib文件及使用
    Qt智能指针QScopedPointer
    Qt的四个常见的图像叠加模式
  • 原文地址:https://www.cnblogs.com/pzk7788/p/10338143.html
Copyright © 2020-2023  润新知