微信公众号开发本地环境开发_如何在5分钟内使HTTPS在本地开发环境上工作
微信公众号开发本地环境开发
Almost any website you visit today is protected by HTTPS. If yours isn’t yet, it should be. Securing your server with HTTPS also means that you can’t send requests to this server from one that isn’t protected by HTTPS. This poses a problem for developers who use a local development environment because all of them run on http://localhost
out-of-the-box.
您今天访问的几乎所有网站都受HTTPS保护。 如果还没有, 应该是 。 使用HTTPS保护服务器的安全还意味着您无法从不受HTTPS保护的服务器向该服务器发送请求。 这给使用本地开发环境的开发人员带来了问题,因为所有开发人员都可以直接在http://localhost
上运行。
At the startup I’m a part of, we decided to secure our AWS Elastic Load Balancer endpoints with HTTPS as part of a move to enhance security. I ran into a situation where my local development environment’s requests to the server started getting rejected.
作为我的一员,我们决定使用HTTPS保护AWS Elastic Load Balancer终端节点,以作为增强安全性的举措的一部分。 我遇到了本地开发环境对服务器的请求开始被拒绝的情况。
A quick Google search later, I found several articles like this, this or this one with detailed instructions on how I could implement HTTPS on localhost
. None of these instructions seemed to work even after I followed them religiously. Chrome always threw a NET::ERR_CERT_COMMON_NAME_INVALID
error at me.
快速谷歌搜索后,我发现像几篇文章这个 , 这个或这个对我怎么能实现HTTPS的详细说明localhost
。 即使我虔诚地遵循了这些指示,这些指示似乎也没有起作用。 Chrome总是向我抛出NET::ERR_CERT_COMMON_NAME_INVALID
错误。
问题 (The problem)
All the detailed instructions I had found were correct for the time they were written. Not anymore.
我发现的所有详细说明在编写时都是正确的。 不再。
After a ton of Googling, I discovered that the reason for my local certificate getting rejected was that Chrome had deprecated support for commonName matching in certificates, in effect, requiring a subjectAltName since January 2017.
经过一番谷歌搜索后,我发现本地证书被拒绝的原因是Chrome自2017年1月起就弃用了证书中对commonName匹配的支持 ,实际上要求提供subjectAltName。
解决方案 (The solution)
We’ll be using OpenSSL to generate all of our certificates.
我们将使用OpenSSL生成所有证书。
步骤1:根SSL证书 (Step 1: Root SSL certificate)
The first step is to create a Root Secure Sockets Layer (SSL) certificate. This root certificate can then be used to sign any number of certificates you might generate for individual domains. If you aren’t familiar with the SSL ecosystem, this article from DNSimple does a good job of introducing Root SSL certificates.
第一步是创建根安全套接字层(SSL)证书。 然后,可以使用此根证书对可能为单个域生成的任何数量的证书进行签名。 如果您不熟悉SSL生态系统, 那么DNSimple的这篇文章可以很好地介绍根SSL证书。
Generate a RSA-2048 key and save it to a file rootCA.key
. This file will be used as the key to generate the Root SSL certificate. You will be prompted for a pass phrase which you’ll need to enter each time you use this particular key to generate a certificate.
生成RSA-2048密钥并将其保存到文件rootCA.key
。 该文件将用作生成根SSL证书的密钥。 每次使用该特定密钥生成证书时,系统都会提示您输入一个密码短语。
openssl genrsa -des3 -out rootCA.key 2048
You can use the key you generated to create a new Root SSL certificate. Save it to a file namedrootCA.pem
. This certificate will have a validity of 1,024 days. Feel free to change it to any number of days you want. You’ll also be prompted for other optional information.
您可以使用生成的密钥来创建新的根SSL证书。 将其保存到名为rootCA.pem
的文件中。 该证书的有效期为1,024天。 随时将其更改为您想要的任何天数。 还将提示您输入其他可选信息。
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem
步骤2:信任根SSL证书 (Step 2: Trust the root SSL certificate)
Before you can use the newly created Root SSL certificate to start issuing domain certificates, there’s one more step. You need to to tell your Mac to trust your root certificate so all individual certificates issued by it are also trusted.
在使用新创建的Root SSL证书开始颁发域证书之前,还有一个步骤。 您需要告诉Mac信任您的根证书,这样它颁发的所有单个证书也将受到信任。
Open Keychain Access on your Mac and go to the Certificates category in your System keychain. Once there, import the rootCA.pem
using File > Import Items. Double click the imported certificate and change the “When using this certificate:” dropdown to Always Trust in the Trust section.
在Mac上打开“钥匙串访问”,然后转到“系统”钥匙串中的“证书”类别。 在那里,使用文件>导入项目导入rootCA.pem
。 双击导入的证书,然后在“信任”部分中将“使用此证书时:”下拉列表更改为“ 始终为真 ”。
Your certificate should look something like this inside Keychain Access if you’ve correctly followed the instructions till now.
如果您到目前为止正确地遵循了说明,那么证书在Keychain Access中应该看起来像这样。
步骤2:网域SSL凭证 (Step 2: Domain SSL certificate)
The root SSL certificate can now be used to issue a certificate specifically for your local development environment located at localhost
.
现在可以使用根SSL证书来颁发专门针对位于localhost
本地开发环境的证书。
Create a new OpenSSL configuration file server.csr.cnf
so you can import these settings when creating a certificate instead of entering them on the command line.
创建一个新的OpenSSL配置文件server.csr.cnf
以便在创建证书时可以导入这些设置,而不用在命令行中输入它们。
[req]
default_bits = 2048
prompt = no
default_md = sha256
distinguished_name = dn[dn]
C=US
ST=RandomState
L=RandomCity
O=RandomOrganization
OU=RandomOrganizationUnit
emailAddress=hello@example.com
CN = localhost
Create a v3.ext
file in order to create a X509 v3 certificate. Notice how we’re specifying subjectAltName
here.
创建一个v3.ext
文件以创建X509 v3证书 。 注意我们如何在此处指定subjectAltName
。
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names[alt_names]
DNS.1 = localhost
Create a certificate key for localhost
using the configuration settings stored in server.csr.cnf
. This key is stored in server.key
.
使用存储在server.csr.cnf
的配置设置为localhost
创建证书密钥。 该密钥存储在server.key
。
openssl req -new -sha256 -nodes -out server.csr -newkey rsa:2048 -keyout server.key -config <( cat server.csr.cnf )
A certificate signing request is issued via the root SSL certificate we created earlier to create a domain certificate for localhost
. The output is a certificate file called server.crt
.
通过我们先前创建的根SSL证书发出证书签名请求,以为localhost
创建域证书。 输出是一个名为server.crt
的证书文件。
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 500 -sha256 -extfile v3.ext
使用新的SSL证书 (Use your new SSL certificate)
You’re now ready to secure your localhost
with HTTPS. Move the server.key
and server.crt
files to an accessible location on your server and include them when starting your server.
现在,您可以使用HTTPS保护localhost
了。 将server.key
和server.crt
文件移动到服务器上的可访问位置,并在启动服务器时将它们包括在内。
In an Express app written in Node.js, here’s how you would do it. Make sure you do this only for your local environment. Do not use this in production.
在用Node.js编写的Express应用程序中,这是您的操作方法。 确保仅针对您的本地环境执行此操作。 不要在生产中使用它 。
I hope you found this tutorial useful. If you’re not comfortable with running the commands given here by yourself, I’ve created a set of handy scripts you can run quickly to generate the certificates for you. More details can be found on the GitHub repo.
希望本教程对您有所帮助。 如果您对自己给定的命令不满意,我创建了一组方便的脚本,可以快速运行这些脚本来为您生成证书。 更多细节可以在GitHub仓库中找到。
I love helping fellow web developers. Follow me on Twitter and let me know if you have any suggestions or feedback. If you’d like to show your appreciation towards any of the work I’ve done, be it a blog post, an open source project or just a funny tweet, you can buy me a cup of coffee.
我喜欢帮助其他Web开发人员。 在Twitter上关注我,如果您有任何建议或反馈,请告诉我。 如果您想对我所做的任何工作表示赞赏,无论是博客文章,开放源代码项目还是有趣的推文,您都可以给我买杯咖啡 。
翻译自: https://www.freecodecamp.org/news/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec/
微信公众号开发本地环境开发
相关文章:

pcntl_fork 导致 MySQL server has gone away 解决方案
pcntl_fork 前连数据库,就会报 MySQL server has gone away 错误。原因是子进程会继承主进程的数据库连接,当mysql返回数据时,这些子进程都可以通过这个连接读到数据,造成数据错乱。 该操作数据库的地方还是要操作数据库ÿ…

[微信小程序]滚动选择器
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 正文: <view class"section"><view class"section__title">普通选择器</view><picker bindchange"bindPickerChange" value"{{ind…

北航MOOC客户端
我们的团队作业终于完成了,欢迎下载使用我们的北航MOOC手机客户端软件(Android端)——北航学堂,学习北航的公开课程。 安装包下载地址: http://pan.baidu.com/s/1jGvH7fS 团队发布博客 http://www.cnblogs.com/sevens/…

大学毕业没有实习经历_我是如何在大学毕业后没有实习的情况下获得第一份开发人员工作的...
大学毕业没有实习经历by Tim Park蒂姆帕克(Tim Park) 我是如何在大学毕业后没有实习的情况下获得第一份开发人员工作的 (How I got my first developer job with no internships straight out of college) 5个关键要素,将在求职中发挥重要作用 (5 key elements tha…

java的线程中断
在java中中断线程可以使用interrupt()函数。此函数虽然不能终止线程的运行,但是可以改变线程的状态为true 即:isInterrupted()的值返回为true 注意:当函数调用了已经被阻塞的线程后,被阻塞的线程将会接收到…
验证表单不为空
有问题可以扫码加我微信,有偿解决问题。承接小程序开发。 微信小程序开发交流qq群 173683895 、 526474645 ; 正文: 目的 : 验证表单是否为空,如果其中一个input的值为空就alert提示它的 name的值不能为空 , <!DOCTYPE html> &…

java中文乱码解决之道(二)—–字符编码详解:基础知识 + ASCII + GB**
原文出处:http://cmsblogs.com/?p1412 在上篇博文(java中文乱码解决之道(一)—–认识字符集)中,LZ简单介绍了主流的字符编码,对各种编码都是点到为止,以下LZ将详细阐述字符集、字符…

swift视图容器_如何使用IBDesignable在Swift中创建漂亮的,可重复使用的渐变视图...
swift视图容器by Lee Dowthwaite通过李道思韦特 如何使用IBDesignable在Swift中创建漂亮的,可重复使用的渐变视图 (How to create a beautiful, reusable gradient view in Swift with IBDesignable) This tutorial will demonstrate how to create a versatile, I…
android 以不规则图片为边框切割另外图片
转自:http://blog.sina.com.cn/s/blog_474928c90101dkvf.html 最近工作上遇到了一个将一个图片按照相框进行裁剪的问题,花了一个下午研究了下,在此整理一下,以便后用。 (相片) …

L3-010. 是否完全二叉搜索树
L3-010. 是否完全二叉搜索树 时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者陈越将一系列给定数字顺序插入一个初始为空的二叉搜索树(定义为左子树键值大,右子树键值小),你需要判断最后的树是否一棵完全二…

[微信小程序]计算自己手机到指定位置的距离
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 正文: 目的: 根据目的地的坐标计算自己手机的位置离目的地的距离的 核心思路: 后续操作必须等所有异步请求都返回了才能继续 使用Promise() const qqmap require("../../utils/qqma…

ai css 线条粗细_如何训练AI将您的设计模型转换为HTML和CSS
ai css 线条粗细by Emil Wallner埃米尔沃尔纳(Emil Wallner) 如何训练AI将您的设计模型转换为HTML和CSS (How you can train an AI to convert your design mockups into HTML and CSS) Within three years, deep learning will change front-end development. It will increa…
Android Layer List 使用实现实例
Layer List是Anroid中的一种图形的方式,它是通过叠加若干张图片的方式来形成最终的图片,最终的图片在代码中表现为一个LayerDrawable对象。 效果图:第一张是默认显示,第二张为按改变按钮后的图 下面通过一个实例来说明:…

Promise - js异步控制神器
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 正文: 首先给来一个简单的demo看看Promise是怎么使用的: <!DOCTYPE html> <html><head><meta charset"utf-8"><script type"text/ja…

lab_2 Selenium
1、安装SeleniumIDE插件 添加组件-搜索Selenium IDE 安装后重启浏览器可以看到工具中存在此IDE 2、学会使用SeleniumIDE录制脚本和导出脚本 工具--Selenium IDE,得到界面如图 以百度搜索天津大学为例,如下图 红色的是录制按钮,base url是当前…

android进度指示器_等待的痛苦—浏览进度指示器地狱的7个级别
android进度指示器by Mike Zetlow由Mike Zetlow 等待的痛苦—浏览进度指示器地狱的7个级别 (The Pain of Waiting — Navigating the 7 Levels of Progress Indicator Hell) How much hell are you willing to put your users through?您愿意让用户承受多少痛苦? …

Oracle基础 动态SQL语句
一、静态SQL和动态SQL的概念。 1、静态SQL 静态SQL是我们常用的使用SQL语句的方式,就是编写PL/SQL时,SQL语句已经编写好了。因为静态SQL是在编写程序时就确定了,我们只能使用SQL中的DML和事务控制语句,但是DDL语句,以及…

dataTables常用参数
一、新版本和老版本的区别 新版本的改进:https://datatables.net/new/1.10 新老版本参数变化列表:http://datatables.club/upgrade/1.10-convert.html 老版本参数列表: http://legacy.datatables.net/usage/features http://legacy.datatable…
[微信小程序]获取用户当前的城市
有问题可以扫码加我微信,有偿解决问题。承接小程序开发。 微信小程序开发交流qq群 173683895 、 526474645 ; 正文: // 获取用户当前位置的名称和城市 util.jsfunction location() {// 实例化腾讯位置服务里面微信小程序JS SDK的API核心…

构建一个react项目_您想要了解更多有关React的内容吗? 让我们构建一个游戏,然后玩。...
构建一个react项目by Samer Buna通过Samer Buna 您想要了解更多有关React的内容吗? 让我们构建一个游戏,然后玩。 (Do you want to learn more about React? Let’s build — and then play — a game.) Update: This article is now part of my book …

vijos 1476 旅游规划题解
题目链接:https://vijos.org/p/1476 解:因为这一定是一棵树,所以我们多画几次图,就会发现所有的最长路径中心点都一样,且中心点把这条最长路径分成两段等长的路。 那么做法就很简单啦,先求出图的最长路径长…

JQ实现导航效果(附效果图)
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 正文: 为了不浪费大家时间, 首先来一张效果图看是不是你需要的 下面是完整的代码和详细的注释. 直接copy就可以用了. html <div id"tab" class"tab"><div…

.NET如何从配置文件中获取连接字符串
一.设置配置文件 <configuration><!--在configuration下创建一个connectionStrings--><connectionStrings><!--以类似键值对的形式,设置好名字和连接字符串--><add name"连接名" connectionString"连接字符串"/>…

javascript 代码_如何使您JavaScript代码保持简单并提高其可读性
javascript 代码by Leonardo Lima莱昂纳多利马(Leonardo Lima) 如何使您JavaScript代码保持简单并提高其可读性 (How to keep your JavaScript code simple and increase its readability) After a few years working almost exclusively with Ruby on Rails and some jQuery,…

《转》Python学习(14)-对文件的操作(一)
转自 http://www.cnblogs.com/BeginMan/p/3166644.html 一、文件对象 我理解的文件对象就是一个接口,通过这个接口对文件进行相关操作。 《Python 核心编程》上说的很晦涩,这里没有深刻理解到,希望有人能解释给我听。 >>> f open(d…

[微信小程序]组件化开发,以一个自定义模块框组件当做示例(附完整示例代码和效果图)
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 自定义组件我把它分为简单的三个步骤, 1.创建组件 --- 2.编写组件 --- 3.调用,使用组件. 第一步:创建组件 创建一个modal文件夹,里面包含 josn.wxml.wcss.js 四个文件,然后在jo…

openstack安装在虚拟机上重启之后无法启动问题
http://www.byywee.com/page/M0/S931/931767.html 运行rejoin-stack.sh脚本的核心: exec screen -c $TOP_DIR/stack-screenrc stack-screenrc文件存储启动的信息: 例如trove的启动 screen -t tr-api bash stuff "/usr/local/bin/trove-api --config…

让我们讨论一下变量,以及为什么要在JavaScript中使用它们。
by Zell Liew由Zell Liew 让我们讨论一下变量,以及为什么要在JavaScript中使用它们。 (Let’s talk about variables — and why you should use them in JavaScript.) The main purpose of coding is to solve problems. For example, what happens when you clic…

Services(服务)
开启服务有两种方式: 如果不会可以看老师的百度音乐盒的案例1、start方式:start方式的生命周期:*服务只会被开启一次,直到用户手动停止 服务才会被销毁*开启需要调用startService 会执行onCreate(),onStartCommand() *注&…

[敏捷开发实践](2) 用于开发和维持复杂产品的敏捷开发框架Scrum
[敏捷开发实践](2) 用于开发和维持复杂产品的敏捷开发框架Scrum 1,Scrum概述 上篇中提到敏捷开发有两种主流的方法,一个是XP,另一个是Scrum,本篇简要介绍Scrum方法。Scrum是一套开发和维护复杂产品的框架或…