微信公众号开发本地环境开发

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.keyserver.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/

微信公众号开发本地环境开发

微信公众号开发本地环境开发_如何在5分钟内使HTTPS在本地开发环境上工作相关推荐

  1. 微信公众号怎么推送消息_微信公众号发送消息

    A.模板消息发送 模板消息仅用于公众号向用户发送重要的服务通知,只能用于符合其要求的服务场景中,如信用卡刷卡通知,商品购买成功通知等.不支持广告等营销类消息以及其它所有可能对用户造成骚扰的消息. 备注 ...

  2. 微信公众号 餐饮 前端源码_成都餐饮茶楼微信公众号开发方案

    在很多人的印象中,传统的餐饮茶楼就应该做好自己的生意,和互联网是拉不上关系的,甚至格格不入.但是就用独立思考的餐饮茶楼客户提出了新的思路,能不能用微信公众号来吸引用户,让微信公众号成为用户的入口,而不 ...

  3. 微信公众号无需二次登录_您无需两次解决问题-您需要一个设计系统

    微信公众号无需二次登录 重点 (Top highlight) The design system concept can be differently defined according to eac ...

  4. 微信公众号云服务器年服务费_微信公众号开发者接口费用高吗

    微信公众号开发者接口费用高吗 很多企业都想开发自己公司的微信公众号,不过大家最关心的还是微信公众号开发价格问题.今天,微速云小编就为大家带来微信公众号开发者接口费用高吗,一起来了解一下吧. 微信公众号 ...

  5. 微信公众号发送小程序卡片_小程序、公众号客服消息可以发送小程序卡片啦

    下面的样式,相信不少人都见过,却极少有人知道它叫什么↓↓↓ 这就是小程序卡片,它是微信小程序分享特有的样式.在微信聊天中,经常可以看到这样的样式. 点击小程序卡片就可以跳转到对应的小程序,简单粗暴的跳 ...

  6. python微信公众号推送_python爬虫_微信公众号推送信息爬取的实例

    问题描述 利用搜狗的微信搜索抓取指定公众号的最新一条推送,并保存相应的网页至本地. 注意点 搜狗微信获取的地址为临时链接,具有时效性. 公众号为动态网页(JavaScript渲染),使用request ...

  7. 微信公众号发送小程序卡片_微信公众号里怎么添加小程序-如何在微信[[公众号]]添加小程序卡片-微信关联小程序...

    参考官方Demo 1.进入公众号,选择「关联小程序」后,微信公众号运营者用手机扫码进行认证,并输入小程序的AppID即可. 2.腾讯地图+小程序appID:wx7643d5f831302ab0 3. ...

  8. 微信公众号发送小程序卡片_如何在公众号文章中添加小程序卡片

    在公众号中添加小程序卡片可以给阅读者更好的文章阅读体验,腾讯地图+小程序可以在文章内容中提供位置卡片和路线规划卡片,适用于各类含有地点信息的文章推文. 绑定腾讯地图+小程序的方法如下: 第一步:公众号 ...

  9. 微信公众号发送小程序卡片_如何在微信 [[公众号]]添加小程序卡片

    参考官方Demo 进入公众号,选择「关联小程序」后,微信公众号运营者用手机扫码进行认证,并输入小程序的 AppID 即可. 腾讯地图+小程序appID:wx7643d5f831302ab0 在这里,可 ...

最新文章

  1. 【Flask】CORS同源问题解决
  2. python用代码表示5与2的整除_Python教程5:Python 2.x和Python 3.x的区别有哪些?
  3. C# 使用 HelpProvider 控件调用帮助文件
  4. HTTP缓存与Spring示例
  5. 使用 jQuery Mobile 与 HTML5 开发 Web App (十八) —— HTML5 Web Workers
  6. redhat自带mysql_rhel4卸载系统自带的mysql4.1
  7. aws cli_学习AWS CLI:AWS CLI概述(AWS命令行界面)
  8. iOS SDK 介绍及导入
  9. 继承(初识继承,继承的进阶)
  10. Nginx重启时丢失nginx.pid文件
  11. 安卓 VNET 抓取 wskey 教程
  12. 输出二叉树中从每个叶子结点到根结点的路径
  13. 手机 download .cu .log_手机清理内存,这些英文文件哪些是可以删除的?看完就知道...
  14. html文件如何创建文件,怎么创建html文件
  15. 电脑之间利用串口传文件
  16. 6 如何保障项目按期完工? 人人都是项目经理系列(第6/13篇)
  17. 沙拉划词+福昕 文献翻译
  18. 51单片机的中断计算
  19. 【Python】OS 模块简介
  20. 画个板子玩一玩STM32F030F4P6,也许是最便宜的32bit MCU

热门文章

  1. 如何给HTML添加事件?
  2. iOS直播(三)GPUImage音视频采集并写入文件
  3. Swift 教學:如何使用iOS Charts API 製作漂亮的圖表
  4. 使用postman修改SAP Marketing Cloud contact主数据
  5. 数据齿轮(DataGear)数据库管理系统 v1.1.1 发布
  6. sklearn:Python语言开发的通用机器学习库
  7. C语言编写的PHP框架--yaf入门编程
  8. ArrayList的内存泄露
  9. Fragment提交transaction导致state loss异常
  10. Animation 模拟纸盒的爆破