1、生成私钥

生成rsa私钥,des3算法,2048位强度。server.key是秘钥文件名,需要提供一个至少4位的密码。

[root@localhost ~]# openssl genrsa -des3 -out server.key 2048
Generating RSA private key, 2048 bit long modulus
........................................................+++
...................................+++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:

2、生成csr(证书签名请求)

创建csr申请签名请求文件,然后发送给证书颁发机构(费用高)、或者实现自签名。

[root@localhost ~]# openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:GuangDong
Locality Name (eg, city) [Default City]:ShenZhen
Organization Name (eg, company) [Default Company Ltd]:OPS
Organizational Unit Name (eg, section) []:OPS
Common Name (eg, your name or your server's hostname) []:www.test.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

3、删除私钥的密码

[root@localhost ~]# ll
total 16
-rw-r--r--   1 root root 1013 Mar  5 15:17 server.csr
-rw-r--r--   1 root root 1751 Mar  5 15:13 server.key
[root@localhost ~]# cp server.key server.key.org
[root@localhost ~]# openssl rsa -in server.key.org -out server.key
Enter pass phrase for server.key.org:
writing RSA key

4、生成自签名证书

[root@localhost ~]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=CN/ST=GuangDong/L=ShenZhen/O=OPS/OU=OPS/CN=www.test.com
Getting Private key

5、apache、nginx设置SSL证书

apache设置SSL证书,并且实现http强制跳转到https

[root@localhost ~]# vi /etc/http/http.conf
LoadModule ssl_module modules/mod_ssl.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule rewrite_module modules/mod_rewrite.so
ServerName www.test.com:80
<Directory "/opt/abc/xyz">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
</Directory>
Include /etc/httpd/extra/httpd-ssl.conf [root@localhost ~]# vi /etc/httpd/extra/httpd-ssl.conf
<VirtualHost _default_:443>
#   General setup for the virtual host
DocumentRoot "/opt/abc/xyz"
ServerName www.test.com:443
ServerAdmin you@example.com
ErrorLog "/usr/local/apache2.4.25/logs/error_log"
TransferLog "/usr/local/apache2.4.25/logs/access_log"
SSLEngine on
SSLCertificateFile "/usr/local/apache/ssl/server.crt"
SSLCertificateKeyFile "/usr/local/apache/ssl/server.key"

nginx设置SSL证书(也可以设置成http强制跳转到https)

[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf
    server {
        listen       443;
        server_name  www.test.com;
        ssl on;
        ssl_certificate server.crt;
        ssl_certificate_key server.key;
[root@localhost ~]# cp server.crt server.key /usr/local/nginx/conf/
[root@localhost ~]# cd /usr/local/nginx/conf/
[root@localhost conf]# ll
总用量 76
-rw-r--r--. 1 root root 1077 4月   5 11:26 fastcgi.conf
-rw-r--r--. 1 root root 1077 4月   5 11:26 fastcgi.conf.default
-rw-r--r--. 1 root root 1007 4月   5 11:26 fastcgi_params
-rw-r--r--. 1 root root 1007 4月   5 11:26 fastcgi_params.default
-rw-r--r--. 1 root root 2837 4月   5 11:26 koi-utf
-rw-r--r--. 1 root root 2223 4月   5 11:26 koi-win
-rw-r--r--. 1 root root 5170 4月   5 11:26 mime.types
-rw-r--r--. 1 root root 5170 4月   5 11:26 mime.types.default
-rw-r--r--. 1 root root 2746 4月   5 15:09 nginx.conf
-rw-r--r--. 1 root root 2656 4月   5 11:26 nginx.conf.default
-rw-r--r--. 1 root root  636 4月   5 11:26 scgi_params
-rw-r--r--. 1 root root  636 4月   5 11:26 scgi_params.default
-rw-r--r--. 1 root root 1200 4月   5 15:10 server.crt
-rw-r--r--. 1 root root 1679 4月   5 15:10 server.key
-rw-r--r--. 1 root root  664 4月   5 11:26 uwsgi_params
-rw-r--r--. 1 root root  664 4月   5 11:26 uwsgi_params.default
-rw-r--r--. 1 root root 3610 4月   5 11:26 win-utf
[root@localhost conf]# systemctl restart nginx

6、访问测试
https://192.168.146.129


https://www.test.com

转载于:https://blog.51cto.com/net881004/2374645

apache、nginx配置openssl自签名证书的更多相关文章

  1. Nginx 配置 HTTPS自签名证书

    工具: OpenSSL ssl的开源实现,几乎实现了市面上所有的加密 libcrypto: 通用加密库, 任何软件要实现加密功能 链接调用这个库 libssl: TLS/SSL 加密库 openssl ...

  2. Nginx配置SSL自签名证书

    生成自签名SSL证书 生成RSA密钥(过程需要设置一个密码,记住这个密码) $ openssl genrsa -des3 -out domain.key 1024 拷贝一个不需要输入密码的密钥文件 $ ...

  3. SSL证书部署HTTPS站点Apache/Nginx配置

    SSL证书及HTTPS协议 SSL 证书是一种数字证书,它使用 Secure Socket Layer 协议在浏览器和 Web 服务器之间建立一条安全通道,从而实现:1.数据信息在客户端和服务器之间的 ...

  4. 用tomcat配置https自签名证书,解决 ios7.1以上系统, 苹果inHouse发布

    用tomcat配置https自签名证书,解决 ios7.1以上系统苹果inHouse发布不能下载安装的问题教程,话说,我其实最讨厌配置某某环境了,因为某一个小环节一旦出错,你的所有工作往往会功亏一篑, ...

  5. 给Nginx配置一个自签名的SSL证书

    转自廖雪峰的官方网站http://www.liaoxuefeng.com/ 要保证Web浏览器到服务器的安全连接,HTTPS几乎是唯一选择.HTTPS其实就是HTTP over SSL,也就是让HTT ...

  6. Nginx配置一个自签名的SSL证书

    http://www.liaoxuefeng.com/article/0014189023237367e8d42829de24b6eaf893ca47df4fb5e000 要保证Web浏览器到服务器的 ...

  7. nginx配置openssl证书

    引用出处: https://blog.csdn.net/liuchunming033/article/details/48470575 证书生成基本步骤: 生成私钥(.key)-->生成证书请求 ...

  8. Linux下生成openssl自签名证书

    校验证书是否被 CA 证书签名,正确的情况: $ openssl verify -CAfile /etc/kubernetes/cert/ca.pem /etc/kubernetes/cert/kub ...

  9. springboot配置SSL自签名证书

    1.证书生成 每一个JDK或者JRE里都有一个工具,叫做:keytool,安装了jdk或jre之后,配置好JAVA环境之后,就可以直接在控制台使用该命令生成自签名证书: 在控制台输入: keytool ...

随机推荐

  1. docker中MySQL镜像数据,日志,配置持久化

    Docker的MySQL8镜像, 实行数据持久化 version: '3.1' services: mysql-itoken-service-admin: restart: always image: ...

  2. ML-Agents(六)Tennis

    目录 ML-Agents(六)Tennis 一.Tennis介绍 二.环境与训练参数 三.场景基本结构 四.代码分析 环境初始化脚本 Agent脚本 Agent初始化与重置 矢量观测空间 Agent动 ...

  3. 1044 Shopping in Mars (25分)(二分查找)

    Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diam ...

  4. PTA数据结构与算法题目集(中文) 7-16

    PTA数据结构与算法题目集(中文)  7-16 7-16 一元多项式求导 (20 分)   设计函数求一元多项式的导数. 输入格式: 以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000 ...

  5. 大数据篇:Hbase

    大数据篇:Hbase Hbase是什么 Hbase是一个分布式.可扩展.支持海量数据存储的NoSQL数据库,物理结构存储结构(K-V). 如果没有Hbase 如何在大数据场景中,做到上亿数据秒级返回. ...

  6. php simplexml_load_string 返回的对象print_r后,丢失信息?

    <?php $content = '<dblp> <inproceedings key="conf/aaim/He07" mdate="2007- ...

  7. 本地代码上传到git仓库(github)

    准备:拥有自己的github账号:电脑上安装了git; 1.进入github,进入仓库点击NEW(新建仓库) 2.新建仓库 Repository name :仓库名称: Description (op ...

  8. Java第七天,类的继承

    面向对象编程的三大特征: 封装.继承.多态 今天我们学习继承! 继承是多态的前提,如果没有继承就没有多态. 继承主要解决的问题就是共性抽取(将许多类共有的特性便作父类,这样可以较大程度的优化代码). ...

  9. java中JVM虚拟机内存模型详细说明

    java中JVM虚拟机内存模型详细说明 2012-12-12 18:36:03|  分类: JAVA |  标签:java  jvm  堆内存  虚拟机  |举报|字号 订阅     JVM的内部结构 ...

  10. Websocket直播间聊天室教程 - GoEasy快速实现聊天室

    最近两年直播那个火啊,真的是无法形容!经常有朋友问起,我想实现一个直播间聊天或者我想开发一个聊天室, 要如何开始呢? 今天小编就手把手的教你用GoEasy做一个聊天室,当然也可以用于直播间内的互动.全 ...