使用 OpenSSL 创建自签名证书

news/2025/1/15 21:50:58/

mkdir -p /etc/nginx/conf.d/cert
#2、创建私钥
openssl genrsa -des3 -out https.key 1024
提示输入字符:
输入字符:rancher
[root@ocean-app-1a-01 cert]# openssl genrsa -des3 -out https.key 1024
Generating RSA private key, 1024 bit long modulus
…++++++
…++++++
e is 65537 (0x10001)
Enter pass phrase for https.key:
139880595519376:error:28069065:lib(40):UI_set_result:result too small:ui_lib.c:831:You must type in 4 to 1023 characters
Enter pass phrase for https.key:
Verifying - Enter pass phrase for https.key:
#3、创建签名请求证书
openssl req -new -key https.key -out https.csr

[root@ocean-app-1a-01 cert]# openssl req -new -key https.key -out https.csr
Enter pass phrase for https.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]:rancher
string is too long, it needs to be less than 2 bytes long
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:BJ
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server’s hostname) []:
Email Address []:
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:rancher
An optional company name []:
#4、在加载SSL支持的Nginx并使用上述私钥时除去必须的口令
$ cp https.key https.key.org
$ openssl rsa -in https.key.org -out https.key

输入 rancher

[root@ocean-app-1a-01 cert]# openssl rsa -in https.key.org -out https.key

输入 rancher

Enter pass phrase for https.key.org:
writing RSA key

#5、最后标记证书使用上述私钥和CSR和有效期
openssl x509 -req -days 365 -in https.csr -signkey https.key -out https.crt
[root@ocean-app-1a-01 cert]# openssl x509 -req -days 365 -in https.csr -signkey https.key -out https.crt
Signature ok
subject=/C=CN/ST=BJ/L=beijing/O=Default Company Ltd
Getting Private key
#6、nginx添加配置如下:

示例

server {
listen 443 ssl; #监听443端口
server_name linking-rancher.di.bigdata;
ssl_certificate /etc/nginx/conf.d/cert/https.crt;
ssl_certificate_key /etc/nginx/conf.d/cert/https.key;
ssl_session_timeout 5m;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding ‘gzip’;

    ##配置使wss协议生效proxy_http_version 1.1;    proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";client_max_body_size 2G;proxy_pass https://rancher;
}
#error_page  404              /404.html;
# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {root   /usr/share/nginx/html;
}

}

实际配置

server {
listen 443 ssl;
server_name linking-rancher.di.bigdata;
ssl_certificate /etc/nginx/conf.d/cert/https.crt;
ssl_certificate_key /etc/nginx/conf.d/cert/https.key;
ssl_session_timeout 5m;
location / {
proxy_pass https://rancher;
proxy_redirect off;
##配置使wss协议生效
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;

    #下面的参数取决环境需要#后端的Web服务器可以通过X-Forwarded-For获取用户真实IPproxy_set_header           Host $host;proxy_set_header           X-Real-IP $remote_addr;proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;client_max_body_size       2G; #允许客户端请求的最大单文件字节数client_body_buffer_size    512k; #缓冲区代理缓冲用户端请求的最大字节数proxy_connect_timeout      300; #nginx跟后端服务器连接超时时间(代理连接超时)proxy_send_timeout         300; #后端服务器数据回传时间(代理发送超时)proxy_read_timeout         300; #连接成功后,后端服务器响应时间(代理接收超时)proxy_buffer_size          4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小proxy_buffers              4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置proxy_busy_buffers_size    64k; #高负荷下缓冲大小(proxy_buffers*2)proxy_temp_file_write_size 64k; #设定缓存文件夹大小fastcgi_buffer_size 128k;fastcgi_buffers 8 128k;fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 128k;
}   
location = /50x.html {root   /usr/share/nginx/html;
}

}

8443 是自动部署rancher 暴露的端口 https协议

upstream rancher{
server 10.0.0.24:8443;
server 10.0.0.24:8080;
}


http://www.ppmy.cn/news/1521668.html

相关文章

JAVA集合的扩容机制

ArrayList List<Integer> list new ArrayList<>(); 不指定初始长度&#xff0c;默认刚开始赋值{}空集合&#xff0c;当 add 时&#xff0c;初始长度为 10。 // 初始容量 private static final int DEFAULT_CAPACITY 10; // 空数组 private static final Objec…

Python 全栈系列266 Kafka服务的Docker搭建

说明 在大量数据处理任务下的缓存与分发 这个算是来自顾同学的助攻1&#xff0c;我有点java绝缘体的体质&#xff0c;碰到和java相关的安装部署总会碰到点奇怪的问题&#xff0c;不过现在已经搞定了。测试也接近了kafka官方标称的性能。考虑到网络、消息的大小等因素&#xff0…

IOS17.0安装巨魔:TrollRestore巨魔发布

&#x1f47b; TrollRestore 17.0 巨魔发布 15.0 - 16.7 RC&#xff08;20H18&#xff09;和17.0。 官网&#xff1a;https://trollrestore.com/ 下载&#xff1a;https://pan.metanetdisk.com/IOS/%E5%B7%A8%E9%AD%94%E7%8E%A9%E5%AE%B6/TrollRestore.com 使用&#xff1a;ht…

点在面内(考虑内环外环)------射线算法

射线算法计算点是否在面内 , 考虑内环和外环的情况 // 判断点是否在线段上 bool on_segment(const studio_point& point, const studio_point& l_beg, const studio_point& l_end) {return std::min(l_beg.lgtd, l_end.lgtd) < point.lgtd && point.lg…

计算机网络 第二章: 物理层概述

文章目录 物理层要实现的功能物理层接口特性机械特性电气特性功能特性过程特性 物理层下面的传输媒体传输媒体的分类 传输方式习题答案 物理层要实现的功能 物理层要实现的功能是在各种传输媒体上, 传输0和1吗进而给其上面的数据链路层提供透明传输比特流的服务. (透明传输比特…

硬件工程师笔试面试知识器件篇——二极管

目录 4、二极管 4.1、基础 二极管原理图 二极管实物图 4.1.1、基本特性 4.1.2、常见类型 4.1.3、工作原理 4.1.4、应用领域 4.2、相关问题 4.2.1、二极管的PN结是如何形成的? 4.2.2、发光二极管(LED)的工作原理是什么? 4.2.3、在电子电路中,二极管通常如何应用?…

MySQL Workbench 的入门指南

前言 MySQL Workbench 是一个官方的图形化工具&#xff0c;用于开发、管理和设计 MySQL 数据库服务器。它提供了丰富的功能&#xff0c;可以帮助数据库管理员、开发者以及DBA们高效地工作。下面是一个MySQL Workbench的入门指南&#xff0c;介绍如何安装和使用它。 安装 MyS…

虚拟机苹果系统MacOS中XCode的安装

1、背景介绍 主机系统Win11&#xff0c;虚拟机VMWare17&#xff0c;苹果系统MacOS 13.6.7 2、Xcode的在线 点击应用市场&#xff0c;输入Xcode搜索&#xff1a; 看来Xcode无法安装在macOS V13上&#xff0c;直接在线安装失败。 3、采用下载安装包的方法进行安装 解决办法参考链…