nginx-自制證書實現

nginx-自制證書實現

  • 一、 確認nginx是支持https功能的
  • 二、生成私鑰
  • 三、 根據ca.key生成nginx web服務器使用的證書簽名請求文件nginx.csr
  • 四、使用ca.key給nginx.csr進行簽名,生成公鑰證書nginx.crt
  • 五、將證書與域名綁定
  • 六、添加域名解析并訪問


一、 確認nginx是支持https功能的

[root@nginx-1 nginx8]# nginx -V
nginx version: nginx/1.29.1
built by gcc 11.5.0 20240719 (Red Hat 11.5.0-5) (GCC)
built with OpenSSL 3.2.2 4 Jun 2024
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx8 --user=scfeng --group=scfeng --with-http_ssl_module --with-http_v2_module --with-http_v3_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-threads

–with-http_ssl_module 支持https功能
–with-http_v2_module 支持http2.0

自制ssl證書,實現nginx的https功能

yum install gcc pcre-devel openssl openssl-devel make -y


二、生成私鑰

CA的私鑰(自己就是CA也是nginx的web服務器),用于簽名證書

[root@localhost ssh]# mkdir /ca
[root@localhost ssh]# cd /ca
[root@localhost ca]# openssl genrsa  -out  ca.key
[root@localhost ca]# ls
ca.key

三、 根據ca.key生成nginx web服務器使用的證書簽名請求文件nginx.csr

nginx.csr 是證書簽名請求文件,包含公鑰和身份信息,用于申請數字證書 --》提交一個申請表格,用來搜集信息的

[root@localhost ca]# openssl req -new -key ca.key -out nginx.csr
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) []:HUNAN
Locality Name (eg, city) [Default City]:changsha
Organization Name (eg, company) [Default Company Ltd]:sanchuang
Organizational Unit Name (eg, section) []:dev
Common Name (eg, your name or your server's hostname) []:www.huang.com
Email Address []:Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@localhost ca]# ls
ca.key  nginx.csr

四、使用ca.key給nginx.csr進行簽名,生成公鑰證書nginx.crt

nginx.crt:生成的數字證書文件,包含服務器的公鑰、身份信息和CA的簽名。

[root@localhost ca]# openssl x509 -req -in nginx.csr -signkey ca.key -out nginx.crt
Certificate request self-signature ok
subject=C=CN, ST=HUNAN, L=changsha, O=sanchuang, OU=devops, CN=www.huang.com, emailAddress=
Getting Private key
[root@localhost ca]# ls
ca.key nginx.crt nginx.csr


五、將證書與域名綁定

全部證書放到/usr/local/nginx編譯安裝的目錄下的conf目錄里

[root@web1 ca]# ls
ca.key nginx.crt nginx.csr
[root@web1 ca]# cp * /usr/local/nginx1/conf/

ssl_certificate nginx.crt;:這一行指定了SSL證書文件的路徑,證書文件名為"nginx.crt"
ssl_certificate_key ca.key;:這一行指定了私鑰文件的路徑。私鑰是與SSL證書相關聯的密鑰,用于解密和驗證服務器證書,私鑰文件名為"ca.key"

[root@web1 conf]# vim nginx.conf
server {listen       443 ssl;http2 on;server_name  www.huang.com;ssl_certificate      nginx.crt;ssl_certificate_key  ca.key;ssl_session_cache    shared:SSL:1m;ssl_session_timeout  5m;ssl_ciphers  HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers  on;location / {root   html;index  index.html index.htm;}}[root@web1 conf]# nginx  -t
nginx: the configuration file /usr/local/nginx1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx1/conf/nginx.conf test is successful
[root@web1 conf]# nginx  -s reload

查看端口(443)

[root@web1 conf]# netstat -anplut|grep nginx
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      691/nginx: master p 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      691/nginx: master p 

六、添加域名解析并訪問

在Windows里添加域名解析

C:\Windows\System32\drivers\etc\hosts
192.168.168.136 www.huang.com

證書是綁定到域名上的,要訪問web服務器的時候,使用域名去訪問 https://www.huang.com

在這里插入圖片描述

效果為瀏覽器地址欄左側的 “不安全”https

Linux系統里添加域名

[root@web1 conf]# vim /etc/hosts
192.168.168.136 www.huang.com

使用curl字符界面瀏覽器去訪問,攜帶公鑰文件

[root@web1 conf]# curl --cacert /ca/nginx.crt https://www.huang.com

http跳轉到https的配置 -> 添加重定向功能

server {listen       80;server_name  www.huang.com;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm; return 301  https://www.huang.com$request_uri ;  #重定向功能
[root@nginx-1 conf]# nginx -t 
nginx: the configuration file /usr/local/nginx8/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx8/conf/nginx.conf test is successful
[root@nginx-1 conf]# nginx -s reload

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/93933.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/93933.shtml
英文地址,請注明出處:http://en.pswp.cn/web/93933.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

FreeRTOS,事件標注組創建,xEventGroupCreate、xEventGroupCreateStatic

1. xEventGroupCreate ():動態創建(臨時借內存) 作用: 向系統(FreeRTOS 的堆內存)“臨時申請” 一塊內存來存放事件組,不需要我們自己提前準備內存。 例子(基于你的代碼修改&#xf…

Linux網絡socket套接字(上)

目錄 前言 1.Socket編程準備 1.理解源IP地址和目的IP地址 2.認識端口號 3.socket源來 4.傳輸層的典型代表 5.網絡字節序 6.socket編程接口 2.Socket編程UDP 1.服務端創建套接字 2.服務端綁定 3.運行服務器 4.客戶端訪問服務器 5.測試 6.補充參考內容 總結 前言…

RK android14 Setting一級菜單IR遙控器無法聚焦問題解決方法

文章目錄 前言 一、問題分析 1.1. 布局文件分析 1.2. Java代碼 二、解決方法 2.1.移除沖突的滾動標志 2.2.解決有問題的初始化調用 2.3.完整補丁 前言 在Android系統Settings應用(packages/apps/Settings)的首頁(SettingsHomepageActivity)中,存在一個 accessibility (無…

iOS 手勢與控件事件沖突解決清單

總結一份「iOS 手勢與控件事件沖突解決清單」,以后你遇到 UIButton / UITableView / UIScrollView 被手勢攔截就能快速排查了:📌 iOS 手勢與控件事件沖突常見解決辦法1?? cancelsTouchesInView👉 最常用,決定手勢識別…

筆試——Day45

文章目錄第一題題目思路代碼第二題題目思路代碼第三題題目思路代碼第一題 題目 kanan和高音 思路 雙指針遍歷數組&#xff0c;更新左右端點并計算最大值 代碼 #include<iostream> #include<vector> using namespace std;int main() {int n; cin >> n;vect…

nnDetection網絡結構分析

基于 RetinaNet 框架擴展&#xff0c;核心用于處理 3D 體積數據&#xff08;如醫學影像 CT/MRI&#xff09;&#xff0c;通過 “Encoder-Decoder-Head” 架構實現多任務學習。以下從整體框架、核心模塊細節、技術特點、應用場景四個維度展開分析。一、整體框架概覽首先通過表格…

Torch -- 卷積學習day4 -- 完整項目流程

完整項目流程總結1. 環境準備與依賴導入import time import os import numpy as np import pandas as pd import torch import torch.nn as nn import torch.optim as optim import torchvision import torchvision.transforms as transforms from torch.utils.data import Dat…

MTK Linux DRM分析(七)- KMS drm_plane.c

一、簡介在 Linux DRM&#xff08;Direct Rendering Manager&#xff09;子系統中&#xff0c;Plane&#xff08;平面&#xff09;代表了一個圖像源&#xff0c;可以在掃描輸出過程中與 CRTC 混合或疊加顯示。每個 Plane 從 drm_framebuffer 中獲取輸入數據&#xff0c;并負責圖…

OpenHarmony之 藍牙子系統全棧剖析:從協議棧到芯片適配的端到端實踐(大合集)

1. 系統架構概述 OpenHarmony藍牙系統采用分層架構設計&#xff0c;基于HDF&#xff08;Hardware Driver Foundation&#xff09;驅動框架和系統能力管理&#xff08;System Ability&#xff09;機制實現。 1.1 架構層次 ┌─────────────────────────…

探索 Ultralytics YOLOv8標記圖片

1、下載YOLOv8模型文件 下載地址&#xff1a;https://docs.ultralytics.com/zh/models/yolov8/#performance-metrics 2、編寫python腳本 aaa.py import cv2 import numpy as np from ultralytics import YOLO import matplotlib.pyplot as pltdef plot_detection(image, box…

Matplotlib數據可視化實戰:Matplotlib子圖布局與管理入門

Matplotlib多子圖布局實戰 學習目標 通過本課程的學習&#xff0c;學員將掌握如何在Matplotlib中創建和管理多個子圖&#xff0c;了解子圖布局的基本原理和調整方法&#xff0c;能夠有效地展示多個數據集&#xff0c;提升數據可視化的效果。 相關知識點 Matplotlib子圖 學習內容…

【python實用小腳本-194】Python一鍵給PDF加水印:輸入文字秒出防偽文件——再也不用開Photoshop

Python一鍵給PDF加水印&#xff1a;輸入文字秒出防偽文件——再也不用開Photoshop PDF加水印, 本地腳本, 零會員費, 防偽標記, 瑞士軍刀 故事開場&#xff1a;一把瑞士軍刀救了投標的你 周五下午&#xff0c;你把 100 頁標書 PDF 發給客戶&#xff0c;卻擔心被同行盜用。 想加水…

開源 C++ QT Widget 開發(四)文件--二進制文件查看編輯

文章的目的為了記錄使用C 進行QT Widget 開發學習的經歷。臨時學習&#xff0c;完成app的開發。開發流程和要點有些記憶模糊&#xff0c;趕緊記錄&#xff0c;防止忘記。 相關鏈接&#xff1a; 開源 C QT Widget 開發&#xff08;一&#xff09;工程文件結構-CSDN博客 開源 C…

【密碼學實戰】X86、ARM、RISC-V 全量指令集與密碼加速技術全景解析

前言 CPU 指令集是硬件與軟件交互的核心橋梁&#xff0c;其設計直接決定計算系統的性能邊界與應用場景。在數字化時代&#xff0c;信息安全依賴密碼算法的高效實現&#xff0c;而指令集擴展則成為密碼加速的 “隱形引擎”—— 從服務器端的高吞吐量加密&#xff0c;到移動端的…

2025-08-21 Python進階2——數據結構

文章目錄1 列表&#xff08;List&#xff09;1.1 列表常用方法1.2 列表的特殊用途1.2.1 實現堆棧&#xff08;后進先出&#xff09;1.2.2 實現隊列&#xff08;先進先出&#xff09;1.3 列表推導式1.4 嵌套列表推導式2 del 語句3 元組&#xff08;Tuple&#xff09;4 集合&…

告別手工編寫測試腳本!Claude+Playwright MCP快速生成自動化測試腳本

在進行自動化測試時&#xff0c;前端頁面因為頻繁迭代UI 結構常有變動&#xff0c;這往往使得自動化測試的腳本往往“寫得快、廢得也快”&#xff0c;維護成本極高。在大模型之前大家往往都會使用錄制類工具&#xff0c;但錄制類工具生成的代碼靈活性較差、定位方式不太合理只能…

一款更適合 SpringBoot 的API文檔新選擇(Spring Boot 應用 API 文檔)

SpringDoc&#xff1a;Spring Boot 應用 API 文檔生成的現代化解決方案 概述 SpringDoc 是一個專為 Spring Boot 應用設計的開源庫&#xff0c;能夠自動生成符合 OpenAPI 3 規范的 API 文檔。它通過掃描項目中的控制器、方法注解及相關配置&#xff0c;動態生成 JSON/YAML/HTML…

文獻閱讀 250821-When and where soil dryness matters to ecosystem photosynthesis

When and where soil dryness matters to ecosystem photosynthesis 來自 <When and where soil dryness matters to ecosystem photosynthesis | Nature Plants> ## Abstract: Background: Projected increases in the intensity and frequency of droughts in the twen…

React學習(九)

目錄&#xff1a;1.react-進階-antd-新增2.react-進階-antd-刪除選中1.react-進階-antd-新增新增代碼&#xff0c;跟需改的代碼類似&#xff0c;直接copy修改組件代碼進行修改userEffect可以先帶著&#xff0c;沒啥用A6組件用到的函數跟修改的也類似&#xff1a;這個useEffect函…

零基礎從頭教學Linux(Day 17)

三層交換機一、三層交換機的配置1.關于如何配置三層交換機&#xff0c;首先我們應該先創建VLANSwitch>en Switch#vlan database % Warning: It is recommended to configure VLAN from config mode,as VLAN database mode is being deprecated. Please consult userdocument…