码迷,mamicode.com
首页 > 微信 > 详细

为微信小程序开发做准备,在Centos 6.8下利用letsencrypt.sh脚本为nginx 配置免费https证书

时间:2017-01-13 16:16:28      阅读:438      评论:0      收藏:0      [点我收藏+]

标签:nginx   微信小程序https配置   免费https   letsencrypt   


原文链接: http://phpecshop.blog.51cto.com/6296699/1891737


最近在做微信小程序商城开发的时候,阅读官方api文档发现要求https,的路程。

wx.request(OBJECT)

wx.request发起的是 HTTPS 请求。


于是开始了在Centos 6.8下利用letsencrypt.sh脚本为nginx 配置免费https(Let‘s Encrypt SSL证书)


1、下载letsencrypt.sh

# wget https://raw.githubusercontent.com/xdtianyu/scripts/master/lets-encrypt/letsencrypt.conf
# wget https://raw.githubusercontent.com/xdtianyu/scripts/master/lets-encrypt/letsencrypt.sh


2、修改letsencrypt.sh文件的参数

# vim letsencrypt.sh

# only modify the values, key files will be generated automaticly.
ACCOUNT_KEY="letsencrypt-account.key" 
DOMAIN_KEY="mtian.net.key"
DOMAIN_DIR="/usr/local/nginx/html"  #网站的根目录
DOMAINS="DNS:mtian.net,DNS:www.mtian.net" #你的网站域名,多个域名用,号分隔
#ECC=TRUE
#LIGHTTPD=TRUE


3、执行文件,生成https所需要的文件

添加执行权限并执行
# chmod +x letsencrypt.sh   
# ./letsencrypt.sh letsencrypt.conf  

运行完成后会在当前目录生成如下文件
letsencrypt-account.key  lets-encrypt-x3-cross-signed.pem  mtian.csr
letsencrypt.conf         mtian.chained.crt                 mtian.net.key
letsencrypt.sh           mtian.crt


5、修改nginx配置文件,加入https

# vim /usr/local/nginx/conf/nginx.conf


   
    server {
        listen       443 ssl;
        server_name  www.mtian.net;

        ssl on;
        
        ssl_certificate /usr/local/nginx/conf/mtian.chained.crt;
        ssl_certificate_key /usr/local/nginx/conf/mtian.net.key;


        location / {
            root   html;
            index  index.html index.htm;
        }
    }


6、复制letsencrypt.sh生成的mtian.chained.crt和mtian.net.key 件到 nginx.conf中指定的目录/usr/local/nginx/conf/

# cp  mtian.chained.crt /usr/local/nginx/conf/
# cp  mtian.net.key  /usr/local/nginx/conf/


7、重启nginx

# service nginx restart

Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]


8、打开浏览器访问https://www.mtian.net/,火狐和谷歌都可以正常访问并且有绿色的锁,https配置完成。

技术分享

技术分享


微信小程序商城http://www.mtian.net/weixinapp.html

Laravel商城http://www.mtian.net/


本文出自 “php ecshop 二次开发” 博客,请务必保留此出处http://phpecshop.blog.51cto.com/6296699/1891737

为微信小程序开发做准备,在Centos 6.8下利用letsencrypt.sh脚本为nginx 配置免费https证书

标签:nginx   微信小程序https配置   免费https   letsencrypt   

原文地址:http://phpecshop.blog.51cto.com/6296699/1891737

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!