如何在 GCE [Wordpress + Apache] 上安装 SSL
How to install SSL on GCE [Wordpress + Apache]
我使用 openssl 命令创建了一个私钥文件:
openssl genrsa -des3 -out private.key 2048
输入我的密码,然后生成 CSR:
openssl req -new -key privatekey.key -out csrkey.csr
我使用此 CSR 密钥通过 RapidSSL 创建我的 SSL 证书。他们向我颁发了 3 个以 .cer 结尾的证书,即:
- CACertificate-1.cer
- CACertificate-2.cer
- ServerCertificate-1.cer
我将所有这些证书上传到 /etc/apache2/ 文件夹
/etc/apache2/ 包含:
- CACertificate-1.cer
- CACertificate-2.cer
- ServerCertificate-1.cer
- Privatekey.key
- Csrkey.csr
- Chain.ctr (I got this from Rapid SSL as an intermidiate certificate)
然后我不得不将代码添加到 /etc/apache2/apache2.conf:
<VirtualHost _default_:443>
SSLEngine on
DocumentRoot /var/www/html
ServerName example.co.uk
SSLEngine on
SSLCertificateFile /etc/apache2/CACertificate-1.cer
SSLCertificateKeyFile /etc/apache2/privatekey.key
SSLCertificateChainFile /etc/apache2/chain.ctr
</VirtualHost>
我的 /etc/apache2/apache2.conf
文件没有 <VirtualHost>
,当我尝试重新启动 apache 时它说 "SSLEngine command not deined in this module"。所以我环顾四周,发现 /etc/apache2/sites-available/default-ssl.conf
确实包含 <VirtualHost>
我继续添加上面的代码,但是在使用
重新启动 apache 之后
sudo apachectl restart
But the https://example.co.uk is giving me a grey screen: SSL connection error
ERR_SSL_PROTOCOL_ERROR Hide details Unable to make a secure connection
to the server. This may be a problem with the server, or it may be
requiring a client authentication certificate that you don't have.
以下是在 Google Compute Engine 上启用 Apache 服务的 HTTPS 协议的步骤(您可以安全地跳过您已经采取的那些步骤):
- 创建一个安全目录来安装和保护您的密钥
$ sudo mkdir /etc/apache2/ssl.crt
$ cd /etc/apache2/ssl.crt
- 生成私钥
$ sudo openssl genrsa -out example.key 2048
- 生成证书签名请求 (CSR)
$ sudo openssl req -new -key example.key -out example.csr
- 您可以使用新的 CSR 从证书颁发机构 (CA) 获取有效证书。或者,您可以通过 运行 以下命令
生成 self-signed 证书
$ sudo openssl x509 -req -days 365 -in example.csr -signkey example.key -out example.crt
Caution: Self-signed certificates are not suitable for public sites.
While a self-signed certificate implements full encryption, it will
cause most browsers to present a warning or error when visitors try to
access your site. The above command is provided for testing purposes
only.
- 打开 Apache 的 SSL 站点配置文件进行编辑
$ sudo nano /etc/apache2/sites-available/default-ssl.conf
- 编辑以下指令的值
SSLCertificateFile /etc/apache2/ssl.crt/example.crt
SSLCertificateKeyFile /etc/apache2/ssl.crt/example.key
- 如果您从 CA 获得证书链文件,请取消注释并编辑 SSLCertificateChainFile 值
SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt
保存配置文件并关闭。
现在启用此站点配置文件
$ sudo a2ensite default-ssl.conf
- 您可以使用下面的命令来验证并查看配置错误
$ sudo apachectl configtest
- 重新启动 Apache 服务
$ sudo service apache2 restart
- Add/Enable 您的 VM 实例的以下 protocol:ports 对的 GCE 防火墙规则
tcp:80 and tcp:443
我使用 openssl 命令创建了一个私钥文件:
openssl genrsa -des3 -out private.key 2048
输入我的密码,然后生成 CSR:
openssl req -new -key privatekey.key -out csrkey.csr
我使用此 CSR 密钥通过 RapidSSL 创建我的 SSL 证书。他们向我颁发了 3 个以 .cer 结尾的证书,即:
- CACertificate-1.cer
- CACertificate-2.cer
- ServerCertificate-1.cer
我将所有这些证书上传到 /etc/apache2/ 文件夹
/etc/apache2/ 包含:
- CACertificate-1.cer
- CACertificate-2.cer
- ServerCertificate-1.cer
- Privatekey.key
- Csrkey.csr
- Chain.ctr (I got this from Rapid SSL as an intermidiate certificate)
然后我不得不将代码添加到 /etc/apache2/apache2.conf:
<VirtualHost _default_:443>
SSLEngine on
DocumentRoot /var/www/html
ServerName example.co.uk
SSLEngine on
SSLCertificateFile /etc/apache2/CACertificate-1.cer
SSLCertificateKeyFile /etc/apache2/privatekey.key
SSLCertificateChainFile /etc/apache2/chain.ctr
</VirtualHost>
我的 /etc/apache2/apache2.conf
文件没有 <VirtualHost>
,当我尝试重新启动 apache 时它说 "SSLEngine command not deined in this module"。所以我环顾四周,发现 /etc/apache2/sites-available/default-ssl.conf
确实包含 <VirtualHost>
我继续添加上面的代码,但是在使用
重新启动 apache 之后sudo apachectl restart
But the https://example.co.uk is giving me a grey screen: SSL connection error
ERR_SSL_PROTOCOL_ERROR Hide details Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have.
以下是在 Google Compute Engine 上启用 Apache 服务的 HTTPS 协议的步骤(您可以安全地跳过您已经采取的那些步骤):
- 创建一个安全目录来安装和保护您的密钥
$ sudo mkdir /etc/apache2/ssl.crt
$ cd /etc/apache2/ssl.crt
- 生成私钥
$ sudo openssl genrsa -out example.key 2048
- 生成证书签名请求 (CSR)
$ sudo openssl req -new -key example.key -out example.csr
- 您可以使用新的 CSR 从证书颁发机构 (CA) 获取有效证书。或者,您可以通过 运行 以下命令 生成 self-signed 证书
$ sudo openssl x509 -req -days 365 -in example.csr -signkey example.key -out example.crt
Caution: Self-signed certificates are not suitable for public sites. While a self-signed certificate implements full encryption, it will cause most browsers to present a warning or error when visitors try to access your site. The above command is provided for testing purposes only.
- 打开 Apache 的 SSL 站点配置文件进行编辑
$ sudo nano /etc/apache2/sites-available/default-ssl.conf
- 编辑以下指令的值
SSLCertificateFile /etc/apache2/ssl.crt/example.crt
SSLCertificateKeyFile /etc/apache2/ssl.crt/example.key
- 如果您从 CA 获得证书链文件,请取消注释并编辑 SSLCertificateChainFile 值
SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt
保存配置文件并关闭。
现在启用此站点配置文件
$ sudo a2ensite default-ssl.conf
- 您可以使用下面的命令来验证并查看配置错误
$ sudo apachectl configtest
- 重新启动 Apache 服务
$ sudo service apache2 restart
- Add/Enable 您的 VM 实例的以下 protocol:ports 对的 GCE 防火墙规则
tcp:80 and tcp:443