iredmail-doc/html/use.a.bought.ssl.certificat...

182 lines
10 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>使用购买的 SSL 证书</title>
<link rel="stylesheet" type="text/css" href="./css/markdown.css" />
</head>
<body>
<div id="navigation">
<a href="https://www.iredmail.org" target="_blank">
<img alt="iRedMail web site"
src="./images/logo-iredmail.png"
style="vertical-align: middle; height: 30px;"
/>&nbsp;
<span>iRedMail</span>
</a>
&nbsp;&nbsp;//&nbsp;&nbsp;<a href="./index.html">Document Index</a></div><div class="admonition note">
<p class="admonition-title">This tutorial is available in other languages. <a href="https://github.com/iredmail/docs">Help translate more</a></p>
<p><a href="./use.a.bought.ssl.certificate.html">English</a> /</p>
</div>
<h1 id="ssl">使用购买的 SSL 证书</h1>
<div class="toc">
<ul>
<li><a href="#ssl">使用购买的 SSL 证书</a><ul>
<li><a href="#ssl-ssl">生成 SSL 密钥并购买 SSL 证书</a></li>
<li><a href="#postfixdovecotapachenginx-ssl">配置 Postfix/Dovecot/Apache/Nginx 使用购买的 SSL 证书</a><ul>
<li><a href="#postfix-smtp">Postfix (SMTP 服务器)</a></li>
<li><a href="#dovecot-pop3imap">Dovecot (POP3/IMAP 服务器)</a></li>
<li><a href="#apache">Apache 网页服务器</a></li>
<li><a href="#nginx">Nginx (网页服务器)</a></li>
<li><a href="#openldap">OpenLDAP</a></li>
</ul>
</li>
<li><a href="#_1">参考资料</a></li>
</ul>
</li>
</ul>
</div>
<p>iRedMail 在安装期间会自动生成一个自签名的 SSL 证书,如果你只是要确保有安全的
网络服务(如基于 SSL/TLS 之上的 POP3/IMAP/SMTP 服务),该证书足以。但某些邮件
客户端或浏览器会弹出一个烦人的警示框,提示你该证书不受信任。为了避免这种提示,
必须从 SSL 证书供应商那里购买 SSL 证书。在 Google 中搜索 <code>buy ssl certificate</code>
会列出许多 SSL 证书供应商,选择你信任的那一家即可。</p>
<blockquote>
<p><a href="https://letsencrypt.org">Let's Encrypt 提供免费的 SSL 证书</a>.</p>
</blockquote>
<h2 id="ssl-ssl">生成 SSL 密钥并购买 SSL 证书</h2>
<p>首先,你需要在服务器上使用 <code>openssl</code> 命令生成一个新的 SSL 证书。<strong>警告</strong> :请
__不要__使用长度小于 2048 位的密钥,那是不安全的。</p>
<pre><code># openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr
</code></pre>
<p>该命令会生成两个文件:</p>
<ul>
<li><code>server.key</code>:密钥文件。可用于解密 SSL 证书。必须保护好这个文件。</li>
<li><code>server.csr</code>:用于申请证书的前面请求文件。<strong>购买 SSL 证书时服务商需要此文件。</strong></li>
</ul>
<p>openssl 命令会依据 X.509 规范的要求提示输入凭据信息:</p>
<ul>
<li><code>Country Name (2 letter code)</code>: 使用两个不带标点符号的字母来表示国别。例如: USCACN。</li>
<li><code>State or Province Name (full name)</code>: 地区或省份全称。例如California。</li>
<li><code>Locality Name (eg, city)</code>: 城市或城镇名称。例如Berkeley。</li>
<li><code>Organization Name (eg, company)</code>: 组织名、公司名。</li>
<li><code>Organizational Unit Name (eg, section)</code>: 申请此凭据的部门或单位。</li>
<li><code>Common Name (e.g. server FQDN or YOUR name)</code>: 服务器域名或申请人名字。</li>
<li><code>Email Address []</code>: 申请人邮箱地址。</li>
<li><code>A challenge password []</code>: 为该 SSL 证书设置一个密码。</li>
<li><code>An optional company name []</code>: 一个可选的备用公司名。</li>
</ul>
<p><strong>注意</strong>:有一些 web 服务器只能识别 <code>Common Name</code> 里指定的服务器地址。例如,使用为
<code>domain.com</code> 申请的证书,用户在访问 <code>www.domain.com</code> 或者 <code>secure.domain.com</code>
的网页时,会被警告当前网站使用的证书不可信,因为 <code>www.domain.com</code>
<code>secure.domain.com</code> 与证书的域名 <code>domain.com</code> 是不同的。</p>
<p>现在有了 <code>server.key</code><code>server.csr</code> 两个文件,前往选定的 SSL 证书供应商
的网站购买证书,它会要求你上传 <code>server.csr</code> 文件或输入该文件的内容,然后就可以
获得签发的 SSL 证书了。</p>
<p>通常情况下, SSL 服务提供商将会给你两个文件:</p>
<ul>
<li>server.crt</li>
<li>server.ca-bundle</li>
</ul>
<p>我们需要着两个文件,以前之前生成的 <code>server.key</code>。将它们上传到服务器,以下是
推荐的存放路径:</p>
<ul>
<li>在 RHEL/CentOS 系统上:<code>server.crt</code><code>server.ca-bundle</code> 上传至
<code>/etc/pki/tls/certs/</code> <code>server.key</code> 上传至 <code>/etc/pki/tls/private/</code></li>
<li>在 Debian/Ubuntu FreeBSD 系统上: <code>server.crt</code><code>server.ca-bundle</code> 上传至
<code>/etc/ssl/certs/</code> <code>server.key</code> 上传至<code>/etc/ssl/private/</code></li>
<li>在 OpenBSD 系统上:上传至 <code>/etc/ssl/</code></li>
</ul>
<h2 id="postfixdovecotapachenginx-ssl">配置 Postfix/Dovecot/Apache/Nginx 使用购买的 SSL 证书</h2>
<p>下面示例中我们以 CentOS 系统为例,请根据你的发行版调整相关文件路径(已在上面注明)。</p>
<h3 id="postfix-smtp">Postfix (SMTP 服务器)</h3>
<p>直接使用 <code>postconf</code> 命令来更新 SSL 证书相关的设置:</p>
<pre><code>postconf -e smtpd_tls_cert_file='/etc/pki/tls/certs/server.crt'
postconf -e smtpd_tls_key_file='/etc/pki/tls/private/server.key'
postconf -e smtpd_tls_CAfile='/etc/pki/tls/certs/server.ca-bundle'
</code></pre>
<p>修改后需重启 Postfix 服务。</p>
<h3 id="dovecot-pop3imap">Dovecot (POP3/IMAP 服务器)</h3>
<p>Dovecot 的 SSL 证书设置定义在主配置文件 <code>/etc/dovecot/dovecot.conf</code>
(Linux/OpenBSD) 或 <code>/usr/local/etc/dovecot/dovecot.conf</code> (FreeBSD) 里:</p>
<pre><code>ssl = required
ssl_cert = &lt;/etc/pki/tls/certs/server.crt
ssl_key = &lt;/etc/pki/tls/private/server.key
ssl_ca = &lt;/etc/pki/tls/certs/server.ca-bundle
</code></pre>
<p>修改后需重启 Dovecot 服务。</p>
<h3 id="apache">Apache 网页服务器</h3>
<ul>
<li>在 RHEL/CentOS 系统上,配置文件为 <code>/etc/httpd/conf.d/ssl.conf</code></li>
<li>在 Debian/Ubuntu 系统上,配置文件为 <code>/etc/apache2/sites-available/default-ssl</code>
(或者是 <code>default-ssl.conf</code> </li>
<li>在 FreeBSD 系统上,配置文件为 <code>/usr/local/etc/apache24/extra/httpd-ssl.conf</code> 。注意:取决于运行的 Apache 版本,右侧路径会有所不同(<code>apache24</code> 将会是 <code>apache[_version_]</code> )。</li>
<li>在 OpenBSD 系统,如果是 OpenBSD 5.5 或更早的版本,配置文件为 <code>/var/www/conf/httpd.conf</code> 。注意: OpenBSD 5.6 以及之后的版本不再装置 Apache 。</li>
</ul>
<p>示例:</p>
<pre><code>SSLCertificateFile /etc/pki/tls/certs/server.crt
SSLCertificateKeyFile /etc/pki/tls/private/server.key
SSLCertificateChainFile /etc/pki/tls/certs/server.ca-bundle
</code></pre>
<p>修改后需重启 Apache 服务。</p>
<h3 id="nginx">Nginx (网页服务器)</h3>
<ul>
<li>在 Linux 和 OpenBSD 系统上, 配置文件为 <code>/etc/nginx/conf.d/default.conf</code></li>
<li>在 FreeBSD 系统上,配置文件为 <code>/usr/local/etc/nginx/conf.d/default.conf</code></li>
</ul>
<pre><code>server {
listen 443;
...
ssl on;
ssl_certificate /etc/pki/tls/certs/server.crt;
ssl_certificate_key /etc/pki/tls/private/server.key;
...
}
</code></pre>
<p>大部分浏览器能识别 SSL 证书,但可能有小部分浏览器无法正确识别。这种情况可以
<code>server.crt</code><code>server.ca-bundle</code> 的内容追加到一个新文件里,然后以这个
新文件作为 SSL 证书。注意:<code>server.crt</code> 的内容要在前面。</p>
<pre><code># cd /etc/pki/tls/certs/
# cat server.crt server.ca-bundle &gt; server.chained.crt
</code></pre>
<p>更新 <code>/etc/nginx/conf.d/default.conf</code> 文件中的 <code>ssl_certificate</code> 参数:</p>
<pre><code> ssl_certificate /etc/pki/tls/certs/server.chained.crt;
</code></pre>
<p>修改后需重启 Nginx 服务。</p>
<h3 id="openldap">OpenLDAP</h3>
<ul>
<li>Red Hat/CentOS配置文件为 <code>/etc/openldap/slapd.conf</code></li>
<li>Debian/Ubuntu配置文件为 <code>/etc/ldap/slapd.conf</code></li>
<li>FreeBSD配置文件为 <code>/usr/local/etc/openldap/slapd.conf</code></li>
<li>OpenBSD配置文件为 <code>/etc/openldap/slapd.conf</code></li>
</ul>
<pre><code>TLSCACertificateFile /etc/pki/tls/certs/server.ca-bundle
TLSCertificateFile /etc/pki/tls/certs/server.crt
TLSCertificateKeyFile /etc/pki/tls/private/server.key
</code></pre>
<p>修改后需重启 OpenLDAP 服务。</p>
<h2 id="_1">参考资料</h2>
<ul>
<li><a href="http://nginx.org/en/docs/http/configuring_https_servers.html">HTTPS 服务器配置</a></li>
</ul><div class="footer">
<p style="text-align: center; color: grey;">All documents are available in <a href="https://github.com/iredmail/docs/">GitHub repository</a>, and published under <a href="http://creativecommons.org/licenses/by-nd/3.0/us/" target="_blank">Creative Commons</a> license. You can <a href="https://github.com/iredmail/docs/archive/master.zip">download the latest version</a> for offline reading. If you found something wrong, please do <a href="https://www.iredmail.org/contact.html">contact us</a> to fix it.</p>
</div>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-3293801-21"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-3293801-21');
</script>
</body></html>