直入主题

使用 openssl 生成文件

建议在 Nginx 配置文件路径内执行

openssl req -x509 -nodes -days 36500 -newkey rsa:2048 -keyout ./nginx.key -out ./nginx.crt

按步骤填写 opt

Country Name (2 letter code) [XX]: CN
State or Province Name (full name) []: <你的地区(任意填写)>
Locality Name (eg, city) [Default City]: <你的地区(任意填写)>
Organization Name (eg, company) [Default Company Ltd]: 回车
Organizational Unit Name (eg, section) []: 回车
# hostname 你需要 https 的
Common Name (eg, your name or your server's hostname) []: localhost
# your Email
Email Address []: xxx@xx.com

配置 Nginx

server {
listen 443 ssl;
server_name localhost;

# 上面 openssl 生成的地址
ssl_certificate /nginx.crt;
ssl_certificate_key /nginx.key;

location / {
root html;
index index.html index.htm;
}

location = /50x.html {
root html;
}
}

Tip:
浏览器如有证书问题同意即可。