背景信息
SSL 证书是加密网站信息并创建更安全的连接的一种方法,而证书当局可以发行验证服务器详细信息的 SSL 证书,但自签证没有第三方证书。
1、安装Apache
如果 Apache 尚未在您的服务器上运行,则这是一个 Apache httpd 包,可供适用使用,名为 apache2 。
运行以下命令来安装:
1sudo apt-get install apache2
要测试包是否正确安装,请在浏览器中输入您的 VPS IP 地址. 如果安装成功,浏览器将显示以下内容:
1It works!
2
3This is the default web page for this server.
4The web server software is running but no content
5has been added, yet.
2)配置 httpd
我们需要配置 httpd 以支持 SSL. 它可以在 httpd 安装中作为 apache2-common 包的一部分。
使用以下命令来启用SSL:
1sudo a2ensite default-ssl
2 sudo a2enmod ssl
这一次,如前所述,让我们重新启动Apache2:
1sudo service apache2 restart
为了测试模块是否正确安装,我们将像以前一样在浏览器中输入我们的 IP 地址;然而,这次我们将使用 https:// 。
第一次访问页面时,浏览器会警告你网站的证书不受信任,你可以继续,你会像以前一样访问相同的页面:
1It works!
2
3This is the default web page for this server.
4The web server software is running but no content has been added,
5yet.
3)生成自签证书
要使用自签名的证书,必须安装包 ssl-cert 。
我想为服务器配置自己的自签证书,并将其存储在 /etc/apache2/ssl 中。
1sudo mkdir /etc/apache2/ssl
当我们要求新证书时,我们可以通过将 365 更改为我们喜欢的天数来指定该证书应有效多久。
1sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
使用此命令,我们将同时创建自签名的SSL证书和保护它的服务器密钥,并将它们都放入新目录中。
此命令会提示终端显示需要填写的字段列表。
最重要的行是共同名称
。在这里输入你的官方域名,或者,如果你还没有一个,你的网站的IP地址。
1<pre>You are about to be asked to enter information that will be incorporated
2into your certificate request.
3What you are about to enter is what is called a Distinguished Name or a DN.
4There are quite a few fields but you can leave some blank
5For some fields there will be a default value,
6If you enter '.', the field will be left blank.
7-----
8Country Name (2 letter code) [AU]:<span class="highlight">US</span>
9State or Province Name (full name) [Some-State]:<span class="highlight">New York</span>
10Locality Name (eg, city) []:<span class="highlight">NYC</span>
11Organization Name (eg, company) [Internet Widgits Pty Ltd]:<span class="highlight">Awesome Inc</span>
12Organizational Unit Name (eg, section) []:<span class="highlight">Dept of Merriment</span>
13Common Name (e.g. server FQDN or YOUR name) []:<span class="highlight">example.com </span>
14Email Address []:<span class="highlight">[email protected]</span></pre><br/>
4)设置证书
现在我们有完成证书的所有必要组件,下一步要做的是设置虚拟主机以显示新证书。
打开 SSL config 文件:
1nano /etc/apache2/sites-available/default-ssl
在以 <VirtualHost _default_43> 开头的部分中,快速进行以下更改。
向服务器管理员电子邮件右下方添加您的服务器名称的行:
1ServerName example.com:443
用 DNS 批准的域名或服务器 IP 地址替换 example.com(它应该与证书上的常用名称相同)。
找到以下三行,并确保它们匹配下面的扩展:
1SSLEngine on
2 SSLCertificateFile /etc/apache2/ssl/apache.crt
3 SSLCertificateKeyFile /etc/apache2/ssl/apache.key
保存和退出文件。
5 激活新的虚拟主机
在在 443 端口上出现的网站能够被激活之前,我们需要启用该虚拟主机:
1sudo a2ensite default
重新启动你的Apache服务器将重新加载它与你的所有更改在场。
1sudo service apache2 reload
在您的浏览器中,键入 https://youraddress,您将能够看到新的证书。
查看更多
一旦您在网站上设置了 SSL 证书,您可以 安装一个 FTP 服务器 如果您还没有这样做。