Fork me on GitHub

windows下openssl安装,证书生成,nginx配置https以及http重定向https

1.下载openssl

http://slproweb.com/download/Win64OpenSSL-1_1_1k.exe

2.解压后环境配置

复制安装bin目录,编辑环境变量path,放入复制的bin目录,点击确认;

 

 

 3.验证环境变量是否配置ok,win+r,输入cmd,然后输入下面的指令:openssl version,可以查看到版本说明安装ok

 

 

 4.证书的生成

4.1. 新建一个文件夹,cmd进入操作台

 

 

 

 

 

 

 4.2 创建服务器私钥,自己选择输入一个密码,然后确认密码

命令:openssl genrsa -des3 -out server.key 2048

 

 

 4.3创建CSR证书请求文件,输入刚刚的密码,然后按提示填写基本信息

命令:openssl req -new -key server.key -out server.csr

 

 

 4.4备份有秘密的私钥文件

命令:copy server.key server.key.orig

 

 

 4.5去掉私钥文件的密码,要输入之前你的密码确认

命令:openssl rsa -in server.key -out server.key

 

 

 4.6使用服务器私钥签署服务器公钥证书

 

 

 命令:openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

 

 

 4.7在之前新建的目录下会出现以下文件

 

 

 

 5.配置nginx,在nginx安装目录下的con文件夹下找到并打开nginx.conf文件

 5.1配置https,找到 # HTTPS server,取消server {}下的注释,并填写以下信息

 

 

     ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

 

5.2 重定向,输入http自动转到htps,找到 # another virtual host using mix of IP-, name-, and port-based configuration,取消server {}下的注释,并填写以下信息

    server {
        listen       80;
        server_name  localhost;
    rewrite ^(.*) https://$server_name$1 permanent; 
        location / {
            root   html;
            index  index.html index.htm;
        }
    }

6.0 重启nginx

分别输入:localhost 和 https:localhost 发现页面都是一样,显示不安全是因为自签证书,浏览器不信任

 

posted @ 2021-07-21 10:48  亲爸爸  阅读(779)  评论(0编辑  收藏  举报