【发布时间】:2017-10-03 10:57:24
【问题描述】:
我想像 https://localhost 一样输入 localhost,我需要使用 ssl 执行此操作。如何在ubuntu的apache服务器中安装SSL证书?
提前致谢
【问题讨论】:
我想像 https://localhost 一样输入 localhost,我需要使用 ssl 执行此操作。如何在ubuntu的apache服务器中安装SSL证书?
提前致谢
【问题讨论】:
您必须将您的证书添加到您的httpd.conf 文件的VirtualHost 部分并将端口更改为433。最小配置如下所示:
LoadModule ssl_module modules/mod_ssl.so
Listen 443
<VirtualHost *:443>
# maybe additional config here
ServerName www.example.com
SSLEngine on
SSLCertificateFile "/path/to/www.example.com.cert"
SSLCertificateKeyFile "/path/to/www.example.com.key"
</VirtualHost>
httpd.conf 应为 /etc/httpd、/etc/apache/ 或类似名称。
之后重启服务器。
更多关于Apache Server SSL的信息。
【讨论】:
Ubuntu 不使用 httpd.conf 作为标准,而是在 /etc/apache2/apache2.conf 中找到 apache 的全局配置内容。您可以在 apache2 目录中创建一个 httpd.conf,并通过在 /etc/apache2/apache2.conf 中包含以下行来从中加载任何进一步的配置。
以下步骤基于带有 Apache2 的 Ubuntu 服务器。 第 1 步:将您的 SSL 证书文件复制/粘贴到服务器。
从您的证书颁发机构(例如 Symantec、GeoTrust、RapidSSL 或 Thawte)下载您的中间证书 (CertificateAuthority.cert) 和 SSL 证书 (Example_Your_Domain.cert)。
将中间证书和 SSL 证书复制到服务器上将保存证书和密钥文件的目录。让它们只能被 root 读取。
第 2 步:找到要编辑的 Apache 配置文件。 一般在 Ubuntu 的 Apache 中可以找到配置文件; /etc/apache2/sites-enabled/example_your_domain
注意:如果在“sites-enabled”文件夹位置找不到配置文件,则必须运行以下命令 “sudo a2ensite example_your_domain” 使用文本编辑器打开配置文件并找到包含 Apache 设置的块。
第 3 步:找到要配置的 SSL 块。 如果您打算同时使用“https”和“http”连接访问您的网站,那么您需要在 /etc/apache2/sites-enabled/ 中有两个单独的文件。一个用于端口 80,另一个用于端口 443。
第 4 步:为“启用 SSL”的网站配置块。 这是为 SSL 证书连接配置的虚拟主机的示例。粗体部分必须配置为在 Ubuntu Server 上与 Apache2 建立 HTTPS 的安全连接
DocumentRoot /var/www/
SSLEngine on
SSLCertificateFile /path/to/example _your _domain.crt
SSLCertificateKeyFile /path/to/your_private.key
SSLCertificateChainFile /path/to/CertificateAuthority.crt
使您的文件名与您的证书文件匹配,例如; SSLCertificateFile 是您的证书文件(例如 example_your_domain.crt)。 SSLCertificateKeyFile 是您在创建 CSR 时生成的密钥文件。 SSLCertificateChainFile 是证书颁发机构的中间证书文件 (Symantec.crt)
第 5 步:就是这样!立即重启 Apache!
【讨论】: