如何为本地主机创建自签名证书?
我已完成 如何使用 https / SSL 中详细说明的步骤在本地主机上? 但这会为我的计算机名称设置一个自签名证书,并且当通过 https://localhost 我收到 IE 警告。
有没有办法为“localhost”创建自签名证书来避免此警告?
I've gone through the steps detailed in How do you use https / SSL on localhost? but this sets up a self-signed cert for my machine name, and when browsing it via https://localhost I receive the IE warning.
Is there a way to create a self-signed cert for "localhost" to avoid this warning?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
由于这个问题被标记为
IIS
,并且我找不到关于如何获得受信任证书的好答案,因此我将给出我的2美分:首先以管理员身份在PowerShell中使用来自@AuriRahimzadeh的命令:
添加了 100 年有效期,以便本地主机的证书不会过期。如果您希望使用
-NotAfter (Get-Date).AddMonths(24)
或任何其他值来代替 24 个月,则可以使用该值。这很好,但证书不受信任,会导致以下错误。这是因为它没有安装在
受信任的根证书颁发机构
中。通过启动
mmc.exe
来解决此问题。然后转到:
文件->添加或删除管理单元 ->证书->添加->电脑账户->本地计算机。单击“完成”。
展开
Personal
文件夹,您将看到您的localhost
证书:将证书复制到
受信任的根证书颁发机构 - 证书
文件夹。最后一步是打开
Internet 信息服务 (IIS) 管理器
或简单地打开inetmgr.exe
。从那里转到您的站点,选择绑定...
和添加...
或编辑...
。设置https
并从下拉列表中选择您的证书。您的证书现已受信任:
Since this question is tagged with
IIS
and I can't find a good answer on how to get a trusted certificate I will give my 2 cents about it:First use the command from @AuriRahimzadeh in PowerShell as administrator:
Added Valid to 100 years so that the cert for localhost hopefully does not expire. You can use
-NotAfter (Get-Date).AddMonths(24)
for 24 months if you want that instead or any other value.This is good but the certificate is not trusted and will result in the following error. It is because it is not installed in
Trusted Root Certification Authorities
.Solve this by starting
mmc.exe
.Then go to:
File -> Add or Remove Snap-ins -> Certificates -> Add -> Computer account -> Local computer. Click Finish.
Expand the
Personal
folder and you will see yourlocalhost
certificate:Copy the certificate into
Trusted Root Certification Authorities - Certificates
folder.The final step is to open
Internet Information Services (IIS) Manager
or simplyinetmgr.exe
. From there go to your site, selectBindings...
andAdd...
orEdit...
. Sethttps
and select your certificate from the drop down.Your certificate is now trusted:
虽然这篇文章被标记为适用于 Windows,但它是 OS X 上的相关问题,我在其他地方还没有看到答案。以下是在 OS X 上为 localhost 创建自签名证书的步骤:
在
Keychain Access
中,双击这个新的 localhost 证书。展开“信任”旁边的箭头并选择“始终信任”。 Chrome 和 Safari 现在应该信任此证书。例如,如果您想将此证书与 node.js 一起使用:Although this post is post is tagged for Windows, it is relevant question on OS X that I have not seen answers for elsewhere. Here are steps to create a self-signed cert for localhost on OS X:
In
Keychain Access
, double-click on this new localhost cert. Expand the arrow next to "Trust" and choose to "Always trust". Chrome and Safari should now trust this cert. For example, if you want to use this cert with node.js:您可以使用 PowerShell 通过 new-selfsignedcertificate cmdlet 生成自签名证书:
注意:makecert.exe 已弃用。
Cmdlet 参考:
https://learn.microsoft。 com/en-us/powershell/module/pki/new-selfsignedcertificate?view=windowsserver2022-ps
You can use PowerShell to generate a self-signed certificate with the new-selfsignedcertificate cmdlet:
Note: makecert.exe is deprecated.
Cmdlet Reference:
https://learn.microsoft.com/en-us/powershell/module/pki/new-selfsignedcertificate?view=windowsserver2022-ps
在这个问题上花费了大量时间后,我发现每当我按照使用 IIS 制作自签名证书的建议时,我发现颁发给和颁发者不正确。 SelfSSL.exe是解决这个问题的关键。以下网站不仅提供了制作自签名证书的分步方法,还解决了颁发给和颁发者问题。 这里是我发现的制作自签名证书的最佳解决方案。如果您希望以视频形式观看相同的教程 点击此处。
SelfSSL 的使用示例如下所示:
SelfSSL /N:CN=YourWebsite.com /V:1000 /S:2
SelfSSL /? 将提供一个列表参数及解释。
After spending a good amount of time on this issue I found whenever I followed suggestions of using IIS to make a self signed certificate, I found that the Issued To and Issued by was not correct. SelfSSL.exe was the key to solving this problem. The following website not only provided a step by step approach to making self signed certificates, but also solved the Issued To and Issued by problem. Here is the best solution I found for making self signed certificates. If you'd prefer to see the same tutorial in video form click here.
A sample use of SelfSSL would look something like the following:
SelfSSL /N:CN=YourWebsite.com /V:1000 /S:2
SelfSSL /? will provide a list of parameters with explanation.
如果您正在尝试创建一个自签名证书,可以让您访问
http://localhost/mysite
然后这是一种创建它的方法
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/32bc5a61-1f7b-4545-a514-a11652f11200
If you are trying to create a self signed certificate that lets you go
http://localhost/mysite
Then here is a way to create it
From http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/32bc5a61-1f7b-4545-a514-a11652f11200
我会推荐 Pluralsight 用于创建自签名证书的工具:
将您的证书制作为 .pfx 并将其导入 IIS。并将其添加为受信任的根证书颁发机构。
I would recomment Pluralsight's tool for creating self-signed-certs: http://blog.pluralsight.com/selfcert-create-a-self-signed-certificate-interactively-gui-or-programmatically-in-net
Make your cert as a .pfx and import it into IIS. And add it as a trusted root cert authority.
生成本地主机证书的最快方法。
Fastest Way to generate localhost certificate.
是和不是。自签名证书会导致该警告消息,因为该证书不是由受信任的证书颁发机构签名的。您可以考虑使用一些选项来删除本地计算机上的此警告。有关详细信息,请参阅此问题排名最高的答案:
我需要做什么才能让 Internet Explorer 8 接受自签名证书?
希望这会有所帮助!
编辑:
抱歉,我最初并不知道您被限制在本地主机上。您可以尝试按照以下链接中的说明“生成具有正确公用名的自签名证书”。
http:// www.sslshopper.com/article-how-to-create-a-self-signed-certificate-in-iis-7.html
Yes and no. Self signed certificates result in that warning message because the certificate was not signed by a trusted Certificate Authority. There are a few options that you can consider to remove this warning on your local machine. See the highest ranked answers to this question for details:
What do I need to do to get Internet Explorer 8 to accept a self signed certificate?
Hope this helps!
EDIT:
Sorry, I wasn't initially aware that you were constrained to localhost. You can attempt to follow the directions on the the link below to "Generate a Self Signed Certificate with the Correct Common Name."
http://www.sslshopper.com/article-how-to-create-a-self-signed-certificate-in-iis-7.html
在 LAN(局域网)中,我们有一台服务器计算机,此处名为 xhost,运行 Windows 10,IIS 被激活为 WebServer。我们必须通过 Google Chrome 之类的浏览器访问这台计算机,不仅可以从服务器本身通过 https://localhost/ 从 localhost 访问,还可以从 LAN 中的其他主机使用 URL https://xhost 访问此计算机/ :
采用这种访问方式,我们没有完全限定的域名,这里只有本地计算机名称xhost。
或者从 WAN:
您应该将 xhost 替换为您真实的本地计算机名称。
上述解决方案都不能令我们满意。经过几天的尝试,我们采用了openssl.exe的解决方案。我们使用 2 个证书 - 由前者认证的 CA(自我认证机构证书)RootCA.crt 和 xhost.crt。我们使用 PowerShell。
1. 创建并更改为安全目录:
2. 生成 RootCA.pem、RootCA.key &RootCA.crt 作为自我认证的证书颁发机构:
3. 提出认证请求:xhost.key、xhost .csr:
4.获得RootCA.pem认证的xhost.crt:
使用extfiledomains.ext文件定义许多安全的访问方式服务器网站:
5. 制作 xhost.pfx PKCS #12,
结合私有 xhost.key 和证书 xhost.crt,允许导入到 iis 中。此步骤要求输入密码,请按[RETURN]键将其清空(无需密码):
iis10 中导入 xhost.pfx
6.在 xhost 计算机(此处为 localhost)中安装的 。并重新启动 IIS 服务。
7. 在端口 443 上将 ssl 与 xhost.local 证书绑定。
重新启动 IIS 服务。
将 RootCA.crt 导入到受信任的根证书颁发机构
8.在任何将访问网站 https://xhost/ 的计算机上,通过 Google Chrome
。 \谷歌浏览器/…/设置
/[高级]/隐私与安全/安全/管理证书
导入 RootCA.crt
浏览器将显示此有效的证书树:
通过 LAN,即使通过 WAN,也不会出现证书错误 https://dev.example.org< /a>.
这是整个 Powershell 脚本 socrt.ps1 文件,用于从零开始生成所有必需的证书文件:
要安装适用于 Windows 的 openSSL,请访问 https://slproweb.com/products/Win32OpenSSL.html
In a LAN (Local Area Network) we have a server computer, here named xhost running Windows 10, IIS is activated as WebServer. We must access this computer via Browser like Google Chrome not only from localhost through https://localhost/ from server itsself, but also from other hosts in the LAN with URL https://xhost/ :
With this manner of accessing, we have not a fully-qualified domain name, but only local computer name xhost here.
Or from WAN:
You shall replace xhost by your real local computer name.
None of above solutions may satisfy us. After days of try, we have adopted the solution openssl.exe. We use 2 certificates - a CA (self certified Authority certificate) RootCA.crt and xhost.crt certified by the former. We use PowerShell.
1. Create and change to a safe directory:
2. Generate RootCA.pem, RootCA.key & RootCA.crt as self-certified Certification Authority:
3. make request for certification: xhost.key, xhost.csr:
4. get xhost.crt certified by RootCA.pem:
with extfile domains.ext file defining many secured ways of accessing the server website:
5. Make xhost.pfx PKCS #12,
combinig both private xhost.key and certificate xhost.crt, permitting to import into iis. This step asks for password, please let it empty by pressing [RETURN] key (without password):
6. import xhost.pfx in iis10
installed in xhost computer (here localhost). and Restart IIS service.
7. Bind ssl with xhost.local certificate on port 443.
Restart IIS Service.
8. Import RootCA.crt into Trusted Root Certification Authorities
via Google Chrome in any computer that will access the website https://xhost/.
\Google Chrome/…/Settings
/[Advanced]/Privacy and Security/Security/Manage certificates
Import RootCA.crt
The browser will show this valid certificate tree:
No Certificate Error will appear through LAN, even through WAN by https://dev.example.org.
Here is the whole Powershell Script socrt.ps1 file to generate all required certificate files from the naught:
To install openSSL for Windows, please visit https://slproweb.com/products/Win32OpenSSL.html
如果您想要快速简单,请运行此
这将立即为您生成一个带有私钥的自签名 x509 证书,在浏览器中
使用简单的 ui 在配置选项卡中设置您的专有名称、dns 名称、ip 地址和证书有效期日期范围,然后点击生成
您可以验证的 证书在线证书证书检查器/解码器
如果您希望您的证书自动受到信任,则必须将其安装到受信任的根存储中,遵循此问题的其他答案中的许多示例
如果您想要快速而仓促,请运行此
我为此创建了一个端点 runkit.com
runkit.com - 来源:生成 https 证书
runkit.com - 端点:生成https证书
端点支持帖子正文中的配置
可以从服务器代码中使用端点,如下所示,这
是为 Node.js生成自签名证书和密钥的代码
删除脚本标签,注释导入语句并取消注释 require 行,这需要 npm install node-forge 它会在本地安装 node-forge 来工作,然后您只需删除该目录即可删除所有内容,
请参阅下面的替代 node.js 方法,该方法不需要安装
我尝试使用 webpack 捆绑 node-forge 以便与 node.js url 导入一起使用,但有点不成功,stackoverflow 对答案的大小有限制,因此请访问撰写文章
github.io:捆绑node-forge
这是我必须解决的问题,在node.js中工作
我在 github.io :生成 https 证书
如果您想跟进此问题、讨论和其他很酷的内容,请加入我们 stackoverflow JavaScript 聊天
if you want it quick and easy, run this
this will generate you a self-signed x509 certificate with private key right now, here in the browser
set your distinguished names, dns names, ip addresses and certificate validity date ranges in the config tab using the simple ui and hit generate certificate
you can verify the certificate online certificate checker / decoder
if you want your certificate to be trusted automatically, you'd have to install it into the trusted root store, following any of the many examples in the other answers to this question
if you want it quick and hasty, run this
i created an endpoint for this on runkit.com
runkit.com - source : generate https certificate
runkit.com - endpoint : generate https certificate
the endpoint supports the config in the post body
the endpoint could be utilised from server code like this
heres the code for generating a self signed certificate and key
for node.js delete the script tags, comment the import statement and uncomment the require line, this requires
npm install node-forge
which installs node-forge locally to work, you can then just delete the directory to get rid of everythingsee below for an alternative node.js method which does not require installing
i attempted to use webpack to bundle node-forge for use with node.js url imports, but was somewhat unsuccessful, stackoverflow has a limit on how big answers can be so please visit for a write up
github.io : bundling node-forge
this is what i had to settle on, works in node.js
i created a more thorough web-ui on github.io : generate https certificate
if you want to follow up on this, discuss and other cool stuff come join us in the stackoverflow javascript chat
你可以尝试 mkcert。
Macos:brew安装mkcert
you could try mkcert.
macos: brew install mkcert
以下是我在 Windows 上为 localhost 获取有效证书所做的操作:
Here's what I did to get a valid certificate for localhost on Windows:
适用于 Windows 10 的解决方案
以上均不适合我,但这个:
1。 按照以下步骤
然后
或此处创建具有单一主题的证书下的步骤进行操作:https://adamtheautomator.com/new-selfsignedcertificate/
您还可以尝试 SAN(创建主题备用名称 (SAN) 证书)。
2.打开 mmc
打开 Windows 搜索并输入 mmc,
然后按照以下步骤操作:
打开文件 > > 添加/删除管理单元,选择证书并单击添加。选择计算机帐户,单击下一步,然后单击完成。
3.将证书从个人复制到受信任
展开 mmc 中证书下的个人
从个人复制新证书受信任的根证书颁发机构
4。为您在 IIS 中的域绑定选择新证书
5.重新启动域/站点
Solution for Windows 10
None of the above worked for me but this one:
1. Follow these steps
then
or steps under Creating A Certificate With a Single Subject here: https://adamtheautomator.com/new-selfsignedcertificate/
You can also try SAN (Creating A Subject Alternative Name (SAN) Certificate).
2. Open mmc
Open Windows search and type mmc
then follow these steps:
Open File > Add/Remove Snap-in, select Certificates and click Add. Select Computer account, click Next and then Finish.
3. Copy certificate from Personal to Trusted
Expand Personal under Certificates in mmc
Copy your new certificate from Personal to Trusted Root Certification Authorities
4. Select the new certificate for your domain binding in IIS
5. Restart the domain/ site
这些是生成 SSL 密钥和证书所需的 OpenSSL 命令。
这里使用的配置文件“openssl.cnf”如下:
检查“localhost”的最后一个 DNS 行。请记住您在第 1 步和第 2 步中提供的密码。 6.
These are the OpenSSL commands need to generate SSL keys and certificates.
The configuration file "openssl.cnf" used here is following:
Check the last DNS line for "localhost". And be remember you password provided in step 1 & 6.