参考链接
Windows系统配置nginx实现https访问
windows下用nginx配置https服务器
nginx server_name 多个
下载nginx并安装
下载,官网 http://nginx.org/en/download.html

解压到自己的目录中

创建ssl目录,准备放置秘钥

启动nginx

第一次访问,http://localhost

安装 OpenSSL
下载,官网 http://slproweb.com/products/Win32OpenSSL.html

下载的文件

安装






安装地址为 D:\Program Files\OpenSSL-Win64\bin 文件夹

配置环境变量,OPENSSL_HOME,%OPENSSL_HOME%\bin



生成https证书
执行cmd命令
# 创建私钥
openssl genrsa -des3 -out nginx.key 1024 #nginx 自定义名称
# 创建 csr 证书
openssl req -new -key nginx.key -out nginx.csr
# 删除密码,复制 nginx.key 并重命名 nginx.key.org
openssl rsa -in nginx.key.org -out nginx.key
# 生成crt证书
openssl x509 -req -days 365 -in nginx.csr -signkey nginx.key -out nginx.crt

增加 nginx 配置
server_name 多个的话,空格隔开就行。很多的话可以用正则。
server {
listen 443 ssl;
server_name localhost.nginx.cn;
ssl_certificate D:/_server/nginx-1.21.3/ssl/nginx.crt;
ssl_certificate_key D:/_server/nginx-1.21.3/ssl/nginx.key;
location / {
root html;
index index.html index.htm;
}
}


配置host文件
C:\Windows\System32\drivers\etc #路径下
127.0.0.1 localhost.nginx.cn #需要配置的域名

重启nginx
nginx -s reload

访问
https://localhost.nginx.cn/



本文档详细介绍了如何在Windows系统上配置nginx以实现HTTPS访问。步骤包括下载和安装nginx及OpenSSL,生成SSL证书,配置nginx服务器块,修改hosts文件,并最终重启nginx以启用HTTPS。通过这些步骤,你可以使本地服务器支持安全的https访问。





