<?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>-Flyぁ梦- &#187; 证书</title>
	<atom:link href="http://blog.11034.org/tag/%e8%af%81%e4%b9%a6/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.11034.org</link>
	<description></description>
	<lastBuildDate>Sun, 22 Jun 2025 08:59:05 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>Tomcat启用https服务</title>
		<link>http://blog.11034.org/2016-06/tomcat_https.html</link>
		<comments>http://blog.11034.org/2016-06/tomcat_https.html#comments</comments>
		<pubDate>Mon, 06 Jun 2016 14:27:44 +0000</pubDate>
		<dc:creator><![CDATA[-Flyぁ梦-]]></dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[HTTPS]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[安全]]></category>
		<category><![CDATA[证书]]></category>

		<guid isPermaLink="false">http://blog.11034.org/?p=2816</guid>
		<description><![CDATA[第一步，获取证书 这个就去百度吧，既有免费证书，也有收费的证书，当然收费的证书会更靠谱更受大众认同（比如Geo [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><span id="more-2816"></span></p>
<h2>第一步，获取证书</h2>
<p>这个就去百度吧，既有免费证书，也有收费的证书，当然收费的证书会更靠谱更受大众认同（比如GeoTrust的）。</p>
<p>然后证书分为3个等级，DV（Domain Validation，证明当前站点在指定域名下，最常见的），OV（Organization Validation，证明当前站点在指定公司or组织下，浏览器会在URL前显示公司名称的），EV（Extended Validation，比OV更加复杂安全的证书，一般为网银所使用）。</p>
<p>这里选择国内的免费证书：https://www.wosign.com/</p>
<p>在它家网站上注册用户，申请免费证书，要填写指定的域名地址和证书保护密码，然后就可以下载到证书了。下载的zip包里有专门供tomcat使用的jks证书。</p>
<h2>第二步，部署https</h2>
<p>将<code class="markdown_inline_code">apache-tomcat/conf/server.xml</code>中原来被注释的&lt;Connector port=&#8221;8443&#8243; &#8230; /&gt;打开，如下配置：</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Connector</span> <span style="color: #000066;">port</span>=<span style="color: #ff0000;">&quot;443&quot;</span> <span style="color: #000066;">protocol</span>=<span style="color: #ff0000;">&quot;org.apache.coyote.http11.Http11NioProtocol&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">acceptCount</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">executor</span>=<span style="color: #ff0000;">&quot;tomcatThreadPool&quot;</span> <span style="color: #000066;">URIEncoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">compression</span>=<span style="color: #ff0000;">&quot;on&quot;</span> <span style="color: #000066;">compressableMimeType</span>=<span style="color: #ff0000;">&quot;text/html,text/css,application/javascript&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">SSLEnabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">scheme</span>=<span style="color: #ff0000;">&quot;https&quot;</span> <span style="color: #000066;">secure</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">clientAuth</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">sslProtocol</span>=<span style="color: #ff0000;">&quot;TLS&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">keystoreFile</span>=<span style="color: #ff0000;">&quot;/home/.../xxx.com.jks&quot;</span> <span style="color: #000066;">keystorePass</span>=<span style="color: #ff0000;">&quot;xxxxxxx&quot;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>这里的配置要和<code class="markdown_inline_code">&lt;Connector port="80"  .../&gt;</code>的配置要完全一致，第一行是基础协议，第二行是优化参数和设置编码，第三行是开启静态资源压缩，最后两行是对于SSL特殊的设置。</p>
<pre class="markdown_pre"><code>在https的Connector中忘记加上URIEncoding="UTF-8"，会导致https中文异常而http正常
（http的&lt;Connector /&gt;自带这个属性）</code></pre>
<h2>第三步，http自动跳转到https</h2>
<p>给<code class="markdown_inline_code">&lt;Connector port="80"  .../&gt;</code>加上属性<code class="markdown_inline_code">redirectPort="443"</code>，这个默认就有。</p>
<p>然后再修改<code class="markdown_inline_code">apache-tomcat/conf/web.xml</code>，最后加上一段：</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Protected Context<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-resource-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- auth-constraint goes here if you requre authentication --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user-data-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transport-guarantee<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CONFIDENTIAL<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/transport-guarantee<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/user-data-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>搞定</p>
<h2>第三步，https的注意事项</h2>
<ul>
<li>在https下，如果页面内还存在有http链接的内容（图片、js等静态资源），则会产生警告，并在浏览器URL栏中失去绿色锁的标志</li>
<li>在https下，如果页面内企图发起http的post请求，则会默认被浏览器禁止，并产生警告</li>
</ul>
<h4  class="related_post_title">看看 HTTPS , Tomcat , 安全 , 证书</h4><ul class="related_post"><li>2016-06-08 -- <a target="_blank" href="http://blog.11034.org/2016-06/tomcat_shutdown.html" title="Tomcat监听shutdown释放数据库连接池">Tomcat监听shutdown释放数据库连接池</a></li><li>2015-08-28 -- <a target="_blank" href="http://blog.11034.org/2015-08/tomcat_linux.html" title="Linux下搭建Tomcat环境">Linux下搭建Tomcat环境</a></li><li>2013-05-20 -- <a target="_blank" href="http://blog.11034.org/2013-05/coyote.html" title="Tomcat的Connector：Coyote">Tomcat的Connector：Coyote</a></li><li>2013-05-19 -- <a target="_blank" href="http://blog.11034.org/2013-05/tomcat6.html" title="Tomcat6源码学习">Tomcat6源码学习</a></li></ul><h4 class="related_post_title">看看 Java </h4><ul class="related_post"><li>2016-09-09 -- <a target="_blank" href="http://blog.11034.org/2016-09/64bits_linux_arena_memory.html" title="64位Linux下Java进程堆外内存迷之64M问题">64位Linux下Java进程堆外内存迷之64M问题</a></li><li>2016-08-18 -- <a target="_blank" href="http://blog.11034.org/2016-08/java_concurrency_in_practice.html" title="读java concurrency in practice">读java concurrency in practice</a></li><li>2016-08-05 -- <a target="_blank" href="http://blog.11034.org/2016-08/thread_stop.html" title="线程清理">线程清理</a></li><li>2016-06-21 -- <a target="_blank" href="http://blog.11034.org/2016-06/futuretask.html" title="FutureTask简单分析和用法">FutureTask简单分析和用法</a></li><li>2016-06-21 -- <a target="_blank" href="http://blog.11034.org/2016-06/semaphore.html" title="Semaphore简单分析">Semaphore简单分析</a></li>]]></content:encoded>
			<wfw:commentRss>http://blog.11034.org/2016-06/tomcat_https.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
