Last active
March 19, 2024 02:31
-
-
Save kiinlam/2579aa350b5e9fb140d3094eff74a2ac to your computer and use it in GitHub Desktop.
Windows下用Nginx配置https服务器
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1、安装openssl:http://slproweb.com/products/Win32OpenSSL.html。 | |
2、设置环境变量 | |
a)新建变量:OPENSSL_HOME => C:\OpenSSL-Win64\bin; | |
b)Path变量添加:%OPENSSL_HOME%。 | |
3、创建私钥 | |
C:\nginx\ssl> openssl genrsa -des3 -out [name].key 1024 | |
[name]为文件名,任意 | |
输入密码,完成 | |
4、创建csr证书 | |
C:\nginx\ssl> openssl req -new -key [name].key -out [name].csr | |
填写信息,CommonName 输入网站域名,如localhost,xxx.yyy.zzz | |
5、创建指纹密码 | |
复制 [name].key并重命名为 [name].key.org | |
C:\nginx\ssl> openssl rsa -in [name].key.org -out [name].key | |
输入密码,完成 | |
6、生成crt证书 | |
C:\nginx\ssl> openssl x509 -req -days 365 -in [name].csr -signkey [name].key -out [name].crt | |
7、修改nginx配置 | |
server { | |
listen 443 ssl; | |
server_name localhost; | |
ssl_certificate C://nginx//ssl//[name].crt; # 这个是证书的crt文件所在目录 | |
ssl_certificate_key C://nginx//ssl//[name].key; # 这个是证书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; # 这个是指定首页的文件名 | |
} | |
} | |
8、nginx重载 | |
C:\nginx> nginx.exe -s reload | |
9、浏览器访问https域名 | |
参考链接:http://mobilesite.github.io/2017/03/11/windows-nginx-https-config/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment