目录
1、创建ssl文件夹用于存放证书。创建私钥 (建议使用系统窗口,不要用gitBash 有涉及到选择的地方,gitBash无法选择)
2、文件夹中生成shidian.key文件 创建csr证书。
3、复制 shidian.key 并重命名 shidian.key.org 执行命令
项目中有需要做接口回调,测试和dev环境都是https方式请求调用没有问题,但是本地调试不通。因为本地启动后端服务都是http请求,所以使用nginx代理,将http请求转换为https请求,方便调试。
Nginx官网:nginx: download

安装到非中文目录下:

启动Nginx:点击nginx.exe文件,启动nginx
然后访问:
访问成功,说明安装nginx成功
OpenSSL官网:Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions

放到一个非中文的目录下去:



首先在Nginx得文件夹中新建一个ssl文件夹:

openssl genrsa -des3 -out shidian.key 1024 //shidian 自己取的名字

可以输入pass作为初始的密码,两次一致。
shidian.key文件 创建csr证书。openssl req -new -key shidian.key -out shidian.csr
此时应该有两个文件:

shidian.key 并重命名 shidian.key.org 执行命令openssl rsa -in shidian.key.org -out shidian.key
openssl x509 -req -days 365 -in shidian.csr -signkey shidian.key -out shidian.crt
最终的文件夹里的内容为:

整个nginx.conf文件配置:
#user nobody;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;#keepalive_timeout 0;
keepalive_timeout 65;#gzip on;
server {
listen 80;
server_name localhost;#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
server {
listen 443 ssl;
server_name localhost;# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
ssl_certificate ..//ssl//shidian.crt;
ssl_certificate_key ..//ssl//shidian.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;
}
}
}
关于ssl配置
server {
listen 443 ssl;
server_name localhost;# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
ssl_certificate ..//ssl//shidian.crt; 指的是ssl证书
ssl_certificate_key ..//ssl//shidian.key; 指的是ssl的密钥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;
}
}

进行https请求访问:

给nginx配置https请求成功!