server在http配置内容如下:
server {
listen 443 ssl; #监听端口,Nginx1.5后推荐使用
server_name www.test.top; #请求域名
ssl_certificate cert/test.top_bundle.pem; #crt证书路径,存放位置Nginx的conf/l文件夹下,可以使用绝对路径
ssl_certificate_key cert/test.top.key; #crt证书key路径
ssl_session_timeout 5m; #会话超时时间
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #加密算法
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #表示使用的TLS协议的类型。
ssl_prefer_server_ciphers on;
# 拦截api请求
location /api/ {
proxy_pass http://localhost:7788/api/; #服务访问地址,内网转发时需要填写内网地址
}
# 拦截所有请求
location / {
root html; #站点目录
index index.html index.htm;
}
微信小程序正式发布版本的时候,需待用https的get接口:
1.调试可用http://test.top:7788/api/
。不需要ngnix转发,直接调用http端口。
2.正式版本改为:https://test.top/api/
。
反向代理的方式,即不改变原本的server配置。直接通过反向代理将test.top/api/重定向到http://test.top:7788/api/
跳转流程:api请求–>80–>443 -->7788