最近在做微信小程式商城開發的時候,閱讀官方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.conf檔的參數
# vim letsencrypt.conf # 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所需的ssl憑證檔
添加执行权限并执行 # 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配置完成。
以上是微信小程式開發在Centos 6.8下利用letsencrypt.sh腳本為nginx設定免費https憑證步驟的詳細內容。更多資訊請關注PHP中文網其他相關文章!