http升级为https--SSL证书

前两天作一个小程序,由于要审核上线才发现微信规定的服务器请求接口是https的,因而乎就为服务器升级html

1:购买SSL证书,能够直接到阿里云上买,由于我是阿里云服务器,所在是在阿里云上面买的免费版证书试试手nginx

2:下载证书配置服务器小程序

买了证书签发完后,能够根据阿里云的开发文档指导配置服务器

 参考网址: https://help.aliyun.com/knowledge_detail/95505.html?spm=5176.2020520154.cas.9.1738U2tQU2tQb4微信

由于个人是Nginx服务器,我就简单说一下Nginx服务器的配置session

  1. 在Nginx的安装目录下建立cert目录,而且将下载的所有文件拷贝到cert目录中。若是申请证书时是本身建立的CSR文件,请将对应的私钥文件放到cert目录下而且命名为a.key;阿里云

  2. 打开 Nginx 安装目录下 conf 目录中的 nginx.conf 文件spa

  3. server { listen 443; server_name localhost; ssl on; root html; index index.html index.htm; ssl_certificate cert/a.pem; ssl_certificate_key cert/a.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; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; }

    4:记得必定要重启nginx服务器。执行:# /usr/local/nginx/sbin/nginx -s reload  重启成功后你的网页就会变成https访问了。code

 

3:可是会出现一个问题,就是用户直接属于域名的话,它还会是访问http,除非手动输入https,这个时候就要监听服务器的80端口,让它跳转到https,须要在nginx.conf 文件下加入如下代码:server

server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent;
 location / { root html; index index.html index.htm; } }

不是加在443端口的server里面,而是有两个server。

这样再重启Nginx服务器,用户一输入域名就会访问到https了。

相关文章
相关标签/搜索