基于Nginx和openssl实现https

[root@localhost ssl]# yum -y install openssl
[root@localhost ssl]# mkdir /usr/local/nginx/conf/ssl/
[root@localhost ssl]# cd /usr/local/nginx/conf/ssl/
[root@localhost ssl]# openssl genrsa -des3 -out server.key 1024 //生成一个私钥(生成私钥的时候会需要一个密码)
[root@localhost ssl]# openssl req -new -key server.key -out server.csr(生成一个公钥,会需要上个密码)
[root@localhost ssl]# cp server.key server.key.org (备份一份密钥文件) 
[root@localhost ssl]# openssl rsa -in server.key.org -out server.key (去除私钥密码)
[root@localhost ssl]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt (导出一个证书文件)
 [root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf (编写nginx主配置文件)
server {
        listen       443 default ssl;
        keepalive_timeout 100;
        server_name  localhost;
        charset utf-8;

        ssl_certificate      /usr/local/nginx/conf/ssl/server.crt;
        ssl_certificate_key  /usr/local/nginx/conf/ssl/server.key;
ssl_session_cache    shared:SSL:10m;
        ssl_session_timeout  10m;

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

 

posted @ 2019-09-24 19:51  会飞的fish  阅读(610)  评论(0编辑  收藏  举报