在nginx上为 IP 地址生成 SSL 证书并在windosw签证

使用 OpenSSL 生成自签名证书

1.1 创建配置文件

创建 ip-san.cnf文件:

bash 复制代码
[ req ]
default_bits = 2048
distinguished_name = req_distinguished_name
req_extensions = req_ext
prompt = no

[ req_distinguished_name ]
countryName = CN
stateOrProvinceName = Beijing
localityName = Beijing
organizationName = MyCompany
commonName = 192.168.1.100  # 您的IP地址

[ req_ext ]
subjectAltName = @alt_names

[ alt_names ]
IP.1 = 192.168.1.100  # 主IP
# 可以添加多个IP
# IP.2 = 10.0.0.1
# DNS.1 = example.com

1.2 生成证书(Linux)

bash 复制代码
# 生成私钥
openssl genrsa -out server.key 2048

# 生成CSR
openssl req -new -key server.key -out server.csr -config ip-san.cnf

# 生成自签名证书(有效期10年)
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt -extfile ip-san.cnf -extensions req_ext

# 生成PFX格式(Windows用)
openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt -password pass:123456

在 Nginx for Windows 使用证书

bash 复制代码
# nginx.conf 配置
server {
    listen 443 ssl;
    server_name 192.168.1.100;
    
    ssl_certificate /nginx/ssl/server.crt;
    ssl_certificate_key /nginx/ssl/server.key;
    
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;
    
    location / {
        root html;
        index index.html;
    }
}

在 Windows 上安装证书

bash 复制代码
# 方法1:图形界面
# 1. 双击 server.pfx
# 2. 选择"本地计算机" → 下一步
# 3. 输入密码 → 勾选"标记此密钥为可导出"
# 4. 选择"根据证书类型,自动选择证书存储" 或
#    选择"个人" → 下一步 → 完成


密码123456




测试 https://192.168.1.100

相关推荐
盛世宏博北京8 小时前
工业环境稳定采集:配电室 IP 温湿度变送器 TCP/UDP 通信部署指南
单片机·tcp/ip·udp
smile0028 小时前
Modbus RTU/TCP通信测试怎么做?从协议要点到自动化回归的完整实践
tcp/ip·回归·自动化
Joy T10 小时前
从 Nginx 到 Gateway 再到微服务:一次 AI 请求的完整链路
nginx·微服务·gateway·controller·路由转发·ai service·接口错误排查
小匠石钧知10 小时前
07_在k8s集群中安装ingress-nginx
nginx·容器·kubernetes·ingress
马六六i11 小时前
市面上专业的IP驱动产业新场景新工具哪家好
网络·人工智能·python·tcp/ip
墨香幽梦客12 小时前
SSL/TLS握手过程全拆解:从ClientHello到Finish的关键步骤与性能优化
网络协议·性能优化·ssl
一只旭宝12 小时前
【网络精讲1】TCP 三次握手:为什么是三次,第三次丢了怎么办
服务器·网络·tcp/ip
百度一下吧1 天前
Nginx 使用手册:从安装配置到实战部署
运维·nginx
木子n11 天前
车载以太网与SOME/IP服务化通信实战-01.从字节到服务:SOME/IP报文解析与四通道开销账
网络·网络协议·tcp/ip·车载以太网·some/ip
沫璃染墨1 天前
从零入门计算机网络系列(一):计算机网络初识——从网络发展史到TCP/IP协议》
linux·网络·网络协议·tcp/ip·计算机网络