Iis 如何为localhost创建自签名证书?
我已经完成了中详细介绍的步骤,但这会为我的机器名设置一个自签名证书,当通过浏览器浏览时,我会收到IE警告Iis 如何为localhost创建自签名证书?,iis,windows-7,ssl-certificate,Iis,Windows 7,Ssl Certificate,我已经完成了中详细介绍的步骤,但这会为我的机器名设置一个自签名证书,当通过浏览器浏览时,我会收到IE警告 是否有方法为“localhost”创建自签名证书以避免此警告?是和否。自签名证书会导致该警告消息,因为该证书未由受信任的证书颁发机构签名。您可以考虑在本地机器上删除此警告的一些选项。有关详细信息,请参阅此问题排名最高的答案: 希望这有帮助 编辑: 很抱歉,我最初不知道您被限制为localhost。您可以尝试按照下面链接上的说明“生成具有正确公用名的自签名证书” 如果您试图创建一个自签名证
是否有方法为“localhost”创建自签名证书以避免此警告?是和否。自签名证书会导致该警告消息,因为该证书未由受信任的证书颁发机构签名。您可以考虑在本地机器上删除此警告的一些选项。有关详细信息,请参阅此问题排名最高的答案: 希望这有帮助
编辑: 很抱歉,我最初不知道您被限制为localhost。您可以尝试按照下面链接上的说明“生成具有正确公用名的自签名证书”
如果您试图创建一个自签名证书,允许您使用
http://localhost/mysite
那么这里有一个创建它的方法
makecert -r -n "CN=localhost" -b 01/01/2000 -e 01/01/2099 -eku 1.3.6.1.5.5.7.3.1 -sv localhost.pvk localhost.cer
cert2spc localhost.cer localhost.spc
pvk2pfx -pvk localhost.pvk -spc localhost.spc -pfx localhost.pfx
从在这个问题上花了很长时间后,我发现每当我遵循使用IIS生成自签名证书的建议时,我发现颁发给和颁发者的证书不正确。SelfSSL.exe是解决此问题的关键。以下网站不仅提供了一种逐步制作自签名证书的方法,而且还解决了“颁发给”和“颁发者”问题。是我找到的制作自签名证书的最佳解决方案。如果你想看同样的视频教程 SelfSSL的示例使用如下所示: SelfSSL/N:CN=YourWebsite.com/V:1000/S:2
SelfSSL/?将提供一个参数列表并进行解释。虽然这篇文章是针对Windows的,但这是OS X上的相关问题,我在其他地方没有看到答案。以下是在操作系统X上为本地主机创建自签名证书的步骤:
# Use 'localhost' for the 'Common name'
openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -keyout localhost.key -out localhost.crt
# Add the cert to your keychain
open localhost.crt
在Keychain Access
中,双击此新的本地主机证书。展开“信任”旁边的箭头并选择“始终信任”。Chrome和Safari现在应该信任此证书。例如,如果您想将此证书用于node.js:
var options = {
key: fs.readFileSync('/path/to/localhost.key').toString(),
cert: fs.readFileSync('/path/to/localhost.crt').toString(),
ciphers: 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES256-SHA384',
honorCipherOrder: true,
secureProtocol: 'TLSv1_2_method'
};
var server = require('https').createServer(options, app);
我建议使用Pluralsight的工具创建自签名证书:
将您的证书设置为.pfx并将其导入IIS。并将其添加为受信任的根证书颁发机构。您可以使用PowerShell使用新的selfsignedcertificate cmdlet生成自签名证书:
New-SelfSignedCertificate -DnsName "localhost" -CertStoreLocation "cert:\LocalMachine\My"
注意:makecert.exe已弃用
Cmdlet引用:
由于此问题标有
IIS
,我找不到一个关于如何获得可信证书的好答案,因此我将为此付出2美分:
首先以管理员身份在PowerShell中使用@AuriRahimzadeh发出的命令:
New-SelfSignedCertificate -DnsName "localhost" -CertStoreLocation "cert:\LocalMachine\My"
这很好,但证书不受信任,将导致以下错误。这是因为它未安装在受信任的根证书颁发机构中
通过启动mmc.exe
解决此问题
然后转到:
文件->添加或删除管理单元->证书->添加->计算机帐户->本地计算机。单击Finish
展开Personal
文件夹,您将看到您的localhost
证书:
将证书复制到受信任的根证书颁发机构-证书
文件夹中
最后一步是打开Internet信息服务(IIS)管理器
,或者只需inetmgr.exe
。从那里转到您的站点,选择Bindings…
和Add…
或Edit…
。设置https
并从下拉列表中选择您的证书
您的证书现在受信任:
如果您使用的是Visual Studio,有一种简单的方法可以使用IIS Express设置和启用SSL您可以尝试使用mkcert macos:brew在LAN(局域网)中安装mkcert。我们有一台服务器计算机,名为xhost,运行Windows 10,IIS作为Web服务器激活。我们必须通过Google Chrome之类的浏览器访问这台计算机,而不仅仅是通过https://localhost/ 来自服务器本身,也来自局域网中URL为https://xhost的其他主机:
https://localhost/
https://xhost/
https://xhost.local/
...
通过这种访问方式,我们没有完全限定的域名,只有本地计算机名xhost
或从广域网:
https://dev.example.org/
...
您应该用您真正的本地计算机名替换xhost
以上任何一种解决方案都不能使我们满意。经过几天的尝试,我们采用了openssl.exe解决方案。我们使用两个证书——CA(自认证机构证书)RootCA.crt和xhost.crt,由前者认证。我们使用PowerShell
1.创建并更改为安全目录:
2.生成RootCA.pem、RootCA.key和RootCA.crt作为自认证证书颁发机构:
3.申请认证:xhost.key,xhost.csr:
4.获得RootCA.pem认证的xhost.crt:
extfile domains.ext文件定义了访问服务器网站的多种安全方式:
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
DNS.2 = xhost
DNS.3 = xhost.local
DNS.4 = dev.example.org
DNS.5 = 192.168.1.2
5.制作xhost.pfx PKCS#12,
组合私有xhost.key和证书xhost.crt,允许导入iis。此步骤要求输入密码,请按[返回]键将其清空(无密码):
6.在iis10中导入xhost.pfx
安装在xhost计算机(此处为localhost)中。然后重新启动IIS服务
IIS10 Gestionnaire des services Internet (IIS) (%windir%\system32\inetsrv\InetMgr.exe)
7.使用端口443上的xhost.local证书绑定ssl。
重新启动IIS服务
8.将RootCA.crt导入受信任的根证书颁发机构
通过Google Chrome在任何可以访问网站的计算机上运行https://xhost/.
\谷歌浏览器/../Settings
/[高级]/隐私和安全/安全/管理证书
导入RootCA.crt
浏览器将显示此有效证书树:
RootCA-CA
|_____ xhost.local
通过LAN,即使通过WAN,也不会出现证书错误。
openssl req -new -nodes -newkey rsa:2048 -keyout xhost.key -out xhost.csr -subj "/C=ZA/ST=FREE STATE/L=Golden Gate Highlands National Park/O=WWF4ME/OU=xhost.home/CN=xhost.local"
openssl x509 -req -sha256 -days 1024 -in xhost.csr -CA RootCA.pem -CAkey RootCA.key -CAcreateserial -extfile domains.ext -out xhost.crt
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
DNS.2 = xhost
DNS.3 = xhost.local
DNS.4 = dev.example.org
DNS.5 = 192.168.1.2
openssl pkcs12 -export -out xhost.pfx -inkey xhost.key -in xhost.crt
IIS10 Gestionnaire des services Internet (IIS) (%windir%\system32\inetsrv\InetMgr.exe)
RootCA-CA
|_____ xhost.local
#
# Generate:
# RootCA.pem, RootCA.key RootCA.crt
#
# xhost.key xhost.csr xhost.crt
# xhost.pfx
#
# created 15-EEC-2020
# modified 15-DEC-2020
#
#
# change to a safe directory:
#
cd C:\users\so\crt
#
# Generate RootCA.pem, RootCA.key & RootCA.crt as Certification Authority:
#
openssl req -x509 -nodes -new -sha256 -days 10240 -newkey rsa:2048 -keyout RootCA.key -out RootCA.pem -subj "/C=ZA/CN=RootCA-CA"
openssl x509 -outform pem -in RootCA.pem -out RootCA.crt
#
# get RootCA.pfx: permitting to import into iis10: not required.
#
#openssl pkcs12 -export -out RootCA.pfx -inkey RootCA.key -in RootCA.crt
#
# get xhost.key xhost.csr:
# C: Country
# ST: State
# L: locality (city)
# O: Organization Name
# OU: Organization Unit
# CN: Common Name
#
openssl req -new -nodes -newkey rsa:2048 -keyout xhost.key -out xhost.csr -subj "/C=ZA/ST=FREE STATE/L=Golden Gate Highlands National Park/O=WWF4ME/OU=xhost.home/CN=xhost.local"
#
# get xhost.crt certified by RootCA.pem:
# to show content:
# openssl x509 -in xhost.crt -noout -text
#
openssl x509 -req -sha256 -days 1024 -in xhost.csr -CA RootCA.pem -CAkey RootCA.key -CAcreateserial -extfile domains.ext -out xhost.crt
#
# get xhost.pfx, permitting to import into iis:
#
openssl pkcs12 -export -out xhost.pfx -inkey xhost.key -in xhost.crt
#
# import xhost.pfx in iis10 installed in xhost computer (here localhost).
#