官网下载
https://www.oomake.com/download/openssl
检查是否安装openssl
D:\tmp\ssl>openssl version
OpenSSL 3.1.0 14 Mar 2023 (Library: OpenSSL 3.1.0 14 Mar 2023)
创建证书密钥文件 server.key
D:\tmp\ssl>openssl genrsa -des3 -out server.key 1024
Enter PEM pass phrase: ## 输入密码
Verifying - Enter PEM pass phrase: ## 输入确认密码
创建证书申请文件:server.csr
D:\tmp\ssl>openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key: ## 输入前面设置的密码
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN ## 输入国家代号,中国输入CN
State or Province Name (full name) [Some-State]:BeiJing ## 省的全名,拼音
Locality Name (eg, city) []:BeiJing ## 市的全名,拼音
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Li ## 公司英文名
Organizational Unit Name (eg, section) []: ## 可以不输入
Common Name (e.g. server FQDN or YOUR name) []: ## 可以不输入
Email Address []: ## 可以不输入
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: ##可以不输入
An optional company name []: ## 可以不输入
备份一份服务器密钥文件 server.key.org
D:\tmp\ssl>copy server.key server.key.org
去除文件口令 server.key
D:\tmp\ssl>openssl rsa -in server.key.org -out server.key
Enter pass phrase for server.key.org: ## 输入前面设置的密码
writing RSA key
生成证书文件server.crt
D:\tmp\ssl>openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Certificate request self-signature ok
subject=C = CN, ST = BeiJing, L = BeiJing, O = Li
此时文件夹内:
nginx配置
server {
listen 443 ssl;
server_name tr.test.com;
ssl_certificate D:/tmp/ssl/server.crt;
ssl_certificate_key D:/tmp/ssl/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;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}