更新2018.06.03
阿里云官方已经提供文档支持,请参考:
最近在开发微信小程序,发现服务器都要求https,因此尝试将原有部署在阿里云上的服务切换为https形式的。以下主要总结阿里云下的nginx如何配置https:
- 申请CA
阿里云提供CA申请服务,入口如下所示:
点击进入,后可以申请免费的CA:
此后,只需要使用阿里云推荐配置申请,即可响应https服务; - 配置nginx
阿里云上使用的是nginx提供web服务,因此需要配置https的443端口,在nginx.conf中:
server {
listen 443 ssl;
server_name wxapp.feblog.top;
ssl_certificate ../temp/214108070190507.pem;
ssl_certificate_key ../temp/214108070190507.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;
proxy_pass http://127.0.0.1:8081;
proxy_redirect default;
}
}
将第一步在阿里云上申请好的key和pem上传到服务器上(不方便ftp时可以利用github中转);
在重启nginx发现报错:
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:99
此时需要在安装包内重新编译安装如下:
- ./configure -with-http_ssl_module
- make
- make install
然后重启nginx,此时打开https://wxapp.feblog.top可以看到: