在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

相关推荐
a8a30211 小时前
Laravel9.x新特性全解析
运维·spring boot·nginx
(Charon)12 小时前
【C++/Qt】Qt 封装 TCP 客户端底层 Network 类:连接、收发、自动测试与错误处理
服务器·网络·qt·tcp/ip
TechWayfarer13 小时前
IP归属地运营商能解决什么问题?风控/增长/数据平台落地实践(附API代码)
开发语言·网络·python·网络协议·tcp/ip
TechWayfarer13 小时前
IP归属地运营商生产落地进阶:缓存+降级+灰度对账全解析
网络·python·网络协议·tcp/ip·缓存
funnycoffee12314 小时前
华为USG防火墙修改tcp aging time , default is 1200S
网络·网络协议·tcp/ip·usg aging time
L16247614 小时前
Nginx 6 种发布方式(滚动发布、蓝绿发布(Blue/Green)、金丝雀发布(Canary 灰度)等) 实操全集(配置 + 分步操作 + 回滚)
运维·nginx
a8a30215 小时前
Laravel5.x进化史:核心特性全解析
nginx·php·laravel
日取其半万世不竭17 小时前
用云服务器部署 Hexo 博客,Nginx 托管静态页面全流程
运维·服务器·nginx
hanyi_qwe17 小时前
Mysql 与 Nginx 双机高可用
数据库·mysql·nginx
IpdataCloud19 小时前
远程办公网络安全中,IP查询工具如何保障数据安全?适用场景与落地指南
tcp/ip·web安全·php