<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>服务器安全维护工作室 &#187; 如何购买廉价 SSL 证书</title>
	<atom:link href="https://www.fuwuqiok.com/tag/%e5%a6%82%e4%bd%95%e8%b4%ad%e4%b9%b0%e5%bb%89%e4%bb%b7-ssl-%e8%af%81%e4%b9%a6/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fuwuqiok.com</link>
	<description></description>
	<lastBuildDate>Sun, 01 Mar 2020 07:28:40 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.26</generator>
	<item>
		<title>如何购买廉价 SSL 证书</title>
		<link>https://www.fuwuqiok.com/%e5%a6%82%e4%bd%95%e8%b4%ad%e4%b9%b0%e5%bb%89%e4%bb%b7-ssl-%e8%af%81%e4%b9%a6/</link>
		<comments>https://www.fuwuqiok.com/%e5%a6%82%e4%bd%95%e8%b4%ad%e4%b9%b0%e5%bb%89%e4%bb%b7-ssl-%e8%af%81%e4%b9%a6/#comments</comments>
		<pubDate>Tue, 01 Dec 2015 14:14:42 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[服务器迁移]]></category>
		<category><![CDATA[网站代维]]></category>
		<category><![CDATA[如何购买廉价 SSL 证书]]></category>

		<guid isPermaLink="false">https://www.fuwuqiok.com/?p=2784</guid>
		<description><![CDATA[<p>添加 GoDaddy SSL 证书到你的网站 为了信息安全，一般网站的用户注册和登录过程会使用加密的 HTTP [&#8230;]</p>
<p><a rel="nofollow" href="https://www.fuwuqiok.com/%e5%a6%82%e4%bd%95%e8%b4%ad%e4%b9%b0%e5%bb%89%e4%bb%b7-ssl-%e8%af%81%e4%b9%a6/">如何购买廉价 SSL 证书</a>，首发于<a rel="nofollow" href="https://www.fuwuqiok.com">服务器安全维护工作室</a>。</p>
]]></description>
				<content:encoded><![CDATA[<h1 class="entry-title">添加 GoDaddy SSL 证书到你的网站</h1>
<div class="entry-content">
<p>为了信息安全，一般网站的用户注册和登录过程会使用加密的 HTTP（即HTTPS）传输用户的帐号和密码，这样可以防止“中间人”盗取帐号资料，这篇文章简述为网站添加SSL证书从而实现 HTTPS 的方法和步骤。下面假如你网站是用 Tomcat 直接搭建的，那么只需如下几个步骤即可：</p>
<ol>
<li>购买 SSL 证书。</li>
<li>在你的服务器上生成一个私密钥匙（Private Key）。</li>
<li>在 SSL 证书销售商那里签名你的 Key。</li>
<li>将已签名的证书导入 Tomcat KeyStore。</li>
<li>修改 Tomcat 的配置并重启 Tomcat 服务。</li>
</ol>
<p>下面详细展开每个步骤</p>
<h2>1、购买 SSL 证书</h2>
<p>为网站添加 HTTPS 功能第一步需要购买一个SSL认证证书，目前使用比较广泛SSL证书认证商有：<a href="http://www.verisign.com/">VeriSign</a> 和 <a href="http://www.thawte.com/">Thawte</a>。不过这些认证商的证书价格不菲，假如你的网站只是想提供加密传输，对安全要求不是非常高，则可以考虑购买 <a href="http://www.godaddy.com/ssl/ssl-certificates.aspx">GoDaddy</a> 的廉价SSL证书.</p>
<h2>2、生成私密钥匙</h2>
<p>使用OpenSSL工具可以很容易生成私钥，不过由于我们准备给Tomcat使用，所以直接使用 Java 自带的 keytool 工具。<br />
转到一个 Tomcat 有权限访问的目录，运行</p>
<pre lang="bash">$ keytool -keysize 2048 -genkey -alias tomcat -keyalg RSA -keystore tomcat.keystore</pre>
<p>然后它会提示你设置一个密码以及输入DN信息：</p>
<pre lang="">Enter keystore password:  设置一个用于保护你keystore文件的密码，例如123456
Re-enter new password: 重复上面的密码
What is your first and last name?
  [Unknown]:  yourdomain.com 输入你网站的域名，注意Godaddy的证书一个只能签名一个域名，也就是说 abc.com 和 www.abc.com 不是同一个域名，这里应该填写你准备签名的那一个域名。
What is the name of your organizational unit?
  [Unknown]:  Networking 组织单位名称（随便）
What is the name of your organization?
  [Unknown]:  yourdomain.com 组织名称（随便）
What is the name of your City or Locality?
  [Unknown]:  Shenzhen 所在城市（随便）
What is the name of your State or Province?
  [Unknown]:  Guangdong 所在省份（随便）
What is the two-letter country code for this unit?
  [Unknown]:  CN 所在国家的两位代号（随便）
Is CN=www.yourdomain.com, OU=Networking, O=yourdomain.com, L=Shenzhen, ST=Guangdong, C=CN correct?
  [no]:  yes 以上信息正确则输入yes

Enter key password for
    (RETURN if same as keystore password): 这一步直接敲回车</pre>
<p>完成后会在当前目录产生一个 tomcat.keystore 文件。</p>
<p>顺便提一下，如果你的网站只在内网自己公司使用，实际上现在的这个 keystore 文件已经可以给 tomcat 使用了，直接跳到第5步即可，不过用浏览器访问你的网站时会提示证书错误（因为没有通过可靠证书销售商签名的缘故）。</p>
<p>回到主题，接着根据此 keystore 文件生成签名请求文件（CSR）：</p>
<pre lang="bash">$ keytool -certreq -keyalg RSA -alias tomcat -file tomcat-yourdomain.csr -keystore tomcat.keystore</pre>
<p>同样地，当它问起密码时，输入刚才设置的密码即可，完成后你会得到一个 tomcat-yourdomain.csr 文件。</p>
<h2>3、到证书销售商签名你的私钥</h2>
<p>登录到你购买 SSL 证书商（<a href="http://www.godaddy.com/ssl/ssl-certificates.aspx">这里是 GoDaddy</a>）， 根据提示进入输入 CSR  的页面，用文本编辑器打开刚才生成的 tomcat-yourdomain.csr 文件，把里面的文本内容复制粘贴到页面的表单里即可。SSL 证书商会根据你的域名发送一封验证邮件到域名注册者的Email（所以你要提前注意你的域名注册的Email地址是什么，如果是错误的话需要先修正，否则 收不到验证Email）。这个过程可能需要几分钟或者几小时，收到验证Email之后点击里面的链接地址就完成私钥签名了。</p>
<h2>4、将证书导入 Tomcat Keystore</h2>
<p>登录到你购买 SSL 的证书商，下载你的网站已签名的证书文件，在 GoDaddy 里你下载会得到一个压缩包，里面放有你的网站证书文件 yourdomain.com.crt，另外还有 GoDaddy 自己的证书（gd_cross_intermediate.crt，gd_intermediate.crt，gd_bundle.crt），这些都需要 导入 tomcat 的 keystore 里的。<br />
GoDaddy 的官方教程有些许错误，经过实验发现正确的过程如下：<br />
a、到<a href="https://certs.godaddy.com/anonymous/repository.seam">这里</a>下载 valicert_class2_root.crt 文件，并导入到 tomcat.keystore：</p>
<pre lang="bash">$ keytool -import -alias root -keystore tomcat.keystore -trustcacerts -file valicert_class2_root.crt</pre>
<p>b、导入 gd_cross_intermediate.crt，gd_intermediate.crt 和你网站的证书 yourdomain.com.crt：</p>
<pre lang="bash">$ keytool -import -alias cross -keystore tomcat.keystore -trustcacerts -file gd_cross_intermediate.crt

$ keytool -import -alias intermed -keystore tomcat.keystore -trustcacerts -file gd_intermediate.crt

$ keytool -import -alias tomcat -keystore tomcat.keystore -trustcacerts -file yourdomain.com.crt</pre>
<h2>5、修改 Tomcat 配置并重启服务</h2>
<p>编辑 Tomcat 的主配置文件 server.xml，在标准的 Connector 下面增加一个 HTTPS 的 Connector，如下：</p>
<pre lang="xml">&lt;Connector port="443″ protocol="HTTP/1.1″ SSLEnabled="true"
    scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS"
    keystoreFile="/PATH/TO/YOUR/FILE/tomcat.keystore"
    keystorePass="123456″ /&gt;</pre>
<p>需要注意这个 Connector 只适用于JIO和NIO类型，如果你的 Tomcat 使用了 <a href="http://apr.apache.org/">APR</a>，则应该参考 Apache Httpd 的证书签名过程（<a href="http://tomcat.apache.org/tomcat-6.0-doc/apr.html#HTTPS">配置方法参考这里</a>） 重启 Tomcat 之后，访问 https://yourdomain.com 应该能看到效果了。</p>
<p>6、其他Web服务程序的证书生成即签名方法</p>
<p>假如你的网站使用了 Apache Httpd、nginx 等Web服务程序，可以参考 <a href="http://community.godaddy.com/help/category/ssl-certificates/186">GoDaddy 相应的官方文档</a>。</p>
<h1 class="entry-title">如何购买廉价 SSL 证书</h1>
<p>网上有不少廉价甚至免费的 SSL 证书服务商，而比较方便快捷的应该是通过 namecheap.com 购买 Comodo Positive SSL 和 RapidSSL，两者都是 $10 左右一年，一般在 10 来分钟之内就能完成。下面是购买的详细步骤：</p>
<h3>1、首先确定你 Web Server 的类型</h3>
<p>一般来说，除了 Java Tomcat Web Server 之外的其他 Web Server（比如 Apache Httpd）都是使用 OpenSSL 实现其加密层的，所以在购买证书时先选定你的 Web Server 加密程序为 OpenSSL。（注：Tomcat 结合 APR 使用的话也是用 OpenSSL 的哦，如果你需要为 Tomcat 购买 SSL 证书，则转到本文第一段提到的那篇旧文。）</p>
<h3>2、生成私钥和签名请求文件</h3>
<p>使用如下命令可以产生一个私钥以及一个签名请求文件</p>
<pre lang="bash">$ openssl req -nodes -newkey rsa:2048 -keyout my.key -out my-request.csr</pre>
<p>这条命令的 rsa:2048 用于指定加密算法的名称以及密钥的长度，最终生成的 my.key 为私钥（要保管好）和一个签名请求文件。</p>
<p>运行这个命令时会询问关你的网站的信息，如果是个人网站，那么大部分资料都是可以随便填的，只要 “Common Name” 这一项准确填写你的域名即可，比如 abc.com，xyz.org，注意不用加 www 前缀，namecheap 代理销售的 SSL 证书会自动额外签名你的 www 二级域名，即付一份价钱，可以同时认证 abc.com 和 www.abc.com。</p>
<h3>3、检查一下你域名登记的 email 地址</h3>
<p>因为证书服务商会验证你的域名，而验证方法则是发送一封 email 到你域名注册时所填写的联系 email 地址，如果你注册域名时是乱填的，记得现在要更正过来了。</p>
<h3>4、把签名请求文件发送给证书服务商</h3>
<p>根据购买流程当中的指引，把第 2 步产生的 my-request.csr 发送给证书服务商。大概等十几分钟（也有时要几个小时）服务商会发送一封 email 给你，一般来说里面包含一个验证码，把这个验证码输入购买流程的页面当中就完成域名验证了。</p>
<h3>5、获取签名证书</h3>
<p>上一步完成之后，大概再等几分钟，你就会收到一封邮件（或者出现在购买流程当中），里面包含有你的证书和证书链。具体来说可能会有这 3 个证书文件：</p>
<ul>
<li>yourDomainName.crt</li>
<li>PositiveSSLCA2.crt</li>
<li>AddTrustExternalCARoot.crt</li>
</ul>
<p>一般来说我们要把后两者合并为一个文件，用记事本打开然后复制粘贴形成一个新文件即可，需要注意 *Root.crt 这个文件的内容要放在最后，对于 linux 系统用户，用这行搞定：</p>
<pre lang="bash">$ cat PositiveSSLCA2.crt AddTrustExternalCARoot.crt &gt; yourDomainName.ca-bundle.crt</pre>
<h3>6、使用证书</h3>
<p>这里以 Apache Httpd 为例，一般的设置如下：</p>
<pre lang="conf">SSLEngine on
SSLCertificateKeyFile /etc/ssl/ssl.key/my.key
SSLCertificateFile /etc/ssl/ssl.crt/yourDomainName.crt
SSLCertificateChainFile /etc/ssl/ssl.crt/yourDomainName.ca-bundle</pre>
<p>如果你的 apache 配置了多个虚拟主机，则配置如下：</p>
<pre lang="conf"># make sure add these lines in somewhere else
#NameVirtualHost *:80
#NameVirtualHost *:443

&lt;VirtualHost *:80&gt;
  ServerName www.your-domain.com
  DocumentRoot /var/www/your-domain
  ServerAlias your-domain.com
&lt;VirtualHost&gt;
&lt;VirtualHost *:443&gt;
  SSLEngine on
  SSLCertificateKeyFile /etc/ssl/ssl.key/my.key
  SSLCertificateFile /etc/ssl/ssl.crt/yourDomainName.crt
  SSLCertificateChainFile /etc/ssl/ssl.crt/yourDomainName.ca-bundle
  ServerName www.your-domain.com  
  DocumentRoot /var/www/your-domain
  ServerName your-domain.com
&lt;VirtualHost&gt;</pre>
<p>对于使用了 APR 的 Tomcat 服务器，配置如下：</p>
<pre lang="conf">&lt;Connector port="443" protocol="HTTP/1.1"
address="198.74.59.36"
SSLEnabled="true"
scheme="https" secure="true"
enableLookups="false"
SSLCertificateFile="/etc/ssl/my/yourDomainName.crt"
SSLCertificateChainFile="/etc/ssl/my/yourDomainName.ca-bundle.crt"
SSLCertificateKeyFile="/etc/ssl/my/my.key"/&gt;</pre>
<p>证书设置完毕。</p>
<h3>7、补：SSL 证书的格式转换</h3>
<p>如果你已经根据上面的流程购买了一个 SSL 证书，而碰巧使用的时候要求是 Java Keystore 格式，那么需要将 OpenSSL 的证书转换一下：</p>
<p>首先将密钥和证书转为 pkcs12 格式：</p>
<pre lang="bash">$ openssl pkcs12 -export -in yourDomainName.crt -inkey my.key &gt; my.p12</pre>
<p>然后将 pkcs12 格式转换为 Java keystore 格式：</p>
<pre lang="bash">$ keytool -importkeystore -srckeystore my.p12 -destkeystore my.jks -srcstoretype pkcs12</pre>
<p>&nbsp;</p>
</div>
<p><a rel="nofollow" href="https://www.fuwuqiok.com/%e5%a6%82%e4%bd%95%e8%b4%ad%e4%b9%b0%e5%bb%89%e4%bb%b7-ssl-%e8%af%81%e4%b9%a6/">如何购买廉价 SSL 证书</a>，首发于<a rel="nofollow" href="https://www.fuwuqiok.com">服务器安全维护工作室</a>。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.fuwuqiok.com/%e5%a6%82%e4%bd%95%e8%b4%ad%e4%b9%b0%e5%bb%89%e4%bb%b7-ssl-%e8%af%81%e4%b9%a6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
