如何在Apache上为CentOS6创建SSL证书

来自菜鸟教程
跳转至:导航、​搜索

状态: 已弃用

本文介绍了不再受支持的 CentOS 版本。 如果您目前正在运行运行 CentOS 6 的服务器,我们强烈建议您升级或迁移到受支持的 CentOS 版本。

原因: CentOS 6 已于 2020 年 11 月 30 日结束生命周期 (EOL) and no longer receives security patches or updates. For this reason, this guide is no longer maintained.

请参阅:
本指南可能仍可用作参考,但可能不适用于其他 CentOS 版本。 如果可用,我们强烈建议使用为您正在使用的 CentOS 版本编写的指南。

以下 DigitalOcean 教程可能很有趣,因为它概述了如何在 CentOS 7 服务器上为 Apache 创建 SSL 证书:




关于自签名证书

SSL 证书是一种加密站点信息并创建更安全连接的方法。 此外,证书可以向站点访问者显示虚拟专用服务器的标识信息。 证书颁发机构可以颁发 SSL 证书来验证虚拟服务器的详细信息,而自签名证书没有第 3 方证实。

第一步——安装 Mod SSL

为了设置自签名证书,我们首先必须确保在我们的 VPS 上安装了 Apache 和 Mod SSL。 您可以使用一个命令安装两者:

yum install mod_ssl

第二步——创建一个新目录

接下来,我们需要创建一个新目录,我们将在其中存储服务器密钥和证书

mkdir /etc/httpd/ssl 

第三步 - 创建自签名证书

当我们请求新证书时,我们可以通过将 365 更改为我们喜欢的天数来指定证书应保持有效的时间。 目前,该证书将在一年后到期。

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/httpd/ssl/apache.key -out /etc/httpd/ssl/apache.crt

使用此命令,我们将创建自签名 SSL 证书和保护它的服务器密钥,并将它们都放入新目录中。

该命令将提示终端显示需要填写的字段列表。

最重要的一行是“通用名称”。 在此处输入您的官方域名,或者,如果您还没有,请输入您网站的 IP 地址。

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:NYC
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Awesome Inc
Organizational Unit Name (eg, section) []:Dept of Merriment
Common Name (e.g. server FQDN or YOUR name) []:example.com                  
Email Address []:webmaster@awesomeinc.com

第四步——设置证书

现在我们有了完成证书所需的所有组件。接下来要做的是设置虚拟主机以显示新证书。

打开 SSL 配置文件:

 vi /etc/httpd/conf.d/ssl.conf

找到以 开头的部分并进行一些快速更改。

取消注释 DocumentRoot 和 ServerName 行并将 example.com 替换为您的 DNS 批准的域名或服务器 IP 地址(它应该与证书上的通用名称相同):

 ServerName example.com:443

找到以下三行,并确保它们与以下扩展名匹配:

SSLEngine on
SSLCertificateFile /etc/httpd/ssl/apache.crt
SSLCertificateKeyFile /etc/httpd/ssl/apache.key 

您的虚拟主机现已全部设置完毕! 保存并退出文件。

第五步——重启 Apache

你完成了。 重新启动 Apache 服务器将重新加载所有更改。

 /etc/init.d/httpd restart

在浏览器中,键入 https://youraddress 以查看新证书。

埃特尔·斯维尔德洛夫