内网nginx配置Https证书

生成CA根证书

生成CA私钥

shell 复制代码
openssl genrsa -out ca.key 2048

生成CA根证书

shell 复制代码
openssl req -x509 -new -nodes -key ca.key -sha256 -days 1024 -out ca.crt

为内网IP生成私钥和证书请求文件(CSR)

生成内外 IP 的私钥

shell 复制代码
openssl genrsa -out server.key 2048

使用私钥生成证书请求文件

shell 复制代码
openssl req -new -key server.key -out server.csr

填写内容与上述CA一致,最后两行直接回车跳过

创建证书扩展文件

为了确保为 内网IP 签名的证书能够用作服务器身份验证,需要为它创建一个扩展文件。创建一个名为 v3.ext 的文件,并添加以下内容

复制代码
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment 
subjectAltName = @alt_names
 
[alt_names]
#这里 IP 替换成 DNS 就可以签名域名了 
IP.1 = 192.168.140.120

使用 CA 的证书为内网 IP 签名证书

shell 复制代码
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 500 -sha256 -extfile v3.ext

部署Nginx

对于nginx 来说,这里得到了 server.crt 和 server.key 就已经可以了对于nginx 来说,这里得到了 server.crt 和 server.key 就已经可以了

复制代码
server {
        listen       443 ssl;
        server_name  localhost;
        
        #ssl证书
        ssl_certificate ../../server.crt; 
        #私钥文件
        ssl_certificate_key ../../server.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;
        }
}
  • 其中 .../.../server.crt和.../.../server.key两个文件需要放入到/etc/nginx文件夹下,否则nginx读不到,可以写绝对路径

参考https://blog.csdn.net/cmy768330962/article/details/134380663

上述参考还有tomcat的配置方式

相关推荐
沃夫上校2 小时前
跨域这件事,其实浏览器在替你挡刀
前端·后端·nginx
Lsetea4 小时前
Java 请求 HTTPS 报 PKIX path building failed:从证书链到 truststore 的完整排查
java·https·ssl证书·keytool·truststore
Lhappy嘻嘻4 小时前
网络(六)|应用层 HTTP&HTTPS:URL、请求响应、Cookie 与证书
网络·http·https
Lsetea7 小时前
Nginx HTTPS证书域名不匹配:用SAN与SNI定位 ERR_CERT_COMMON_NAME_INVALID
nginx·https·ssl证书·openssl·tls
Larru-Sun8 小时前
Nginx + Vue Router 基础:SPA History 部署、反向代理与请求分流
运维·vue.js·nginx
迷途呀18 小时前
CI/CD 自动化部署实践:让代码提交后自动上线
linux·运维·nginx·ci/cd·自动化
企业数字化笔记1 天前
AI写的网站一直自动跳转怎么办?301、302和HTTPS重定向排查
网络协议·http·https
运维全栈笔记1 天前
Ansible 自动化 Nginx 集群部署实战:动态 Inventory、滚动发布与 Role 工程化
nginx·自动化·ansible
2501_915106322 天前
苹果App Store上架费用及流程全面解析
android·ios·小程序·https·uni-app·iphone·webview
阿标在干嘛2 天前
Nginx一个配置错误,流量损失30%!这是我们的完整排查记录
运维·nginx