如何正确启用ubuntu apache2 ec2实例上的SSL?

我已经build立了一个Ubuntu的(14.04.2)apache2(2.4.7)服务器的SSL,但似乎没有find证书。 Ubuntu运行在具有静态IP的EC2实例上,启用了443端口,域名为theaudioserver.com,DNSlogging为该静态IP。 以下是我如何设置我的服务器:

  • 创build键: openssl genrsa 2048 > privatekey.pem
  • 生成的证书请求: openssl req -new -key privatekey.pem -out csr.pem
  • 用csr购买了一个CA SSL证书,并将密钥保存到server.crtserver_bundle.crt
  • 在/ etc / apache2 / sites-available中添加ssl.conf文件,该文件configuration为SSL:
  SSLStaplingCache shmcb:/tmp/stapling_cache(128000) <VirtualHost *:443> SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH SSLProtocol All -SSLv2 -SSLv3 SSLHonorCipherOrder On Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload" Header always set X-Frame-Options DENY Header always set X-Content-Type-Options nosniff SSLCompression off SSLUseStapling on ServerName theaudioserver.com SSLEngine on SSLCertificateFile /home/ubuntu/certs/server.crt SSLCertificateKeyFile /home/ubuntu/certs/privatekey.pem SSLCertificateChainFile /home/ubuntu/certs/server_bundle.crt DocumentRoot /var/www/html/ </VirtualHost> 
  • sudo a2enmod ssl添加SSL
  • 重新启动apache2成功(在日志中没有任何错误)
  • 我也检查,如果apache2正在听443,它似乎听同情: sudo netstat -anp | grep apache sudo netstat -anp | grep apache给出: tcp6 0 0 :::443 :::* LISTEN 3138/apache2

但是当我testing我的域名时,证书似乎没有被发现。

在ssllabs.com上,我收到了在theaudioserver.com上No SSL certificates were found on theaudioserver.com. Make sure that the name resolves to the correct server and that the SSL port (default is 443) is open on your server's firewall No SSL certificates were found on theaudioserver.com. Make sure that the name resolves to the correct server and that the SSL port (default is 443) is open on your server's firewall

当通过https://52.24.39.220访问服务器时,我得到一个名称不匹配的错误,因为我没有通过域名访问,但这表明EC2上的服务器防火墙似乎设置正确。

我在这里做错了什么?

我没有得到任何连接到您的服务器端口443感觉就像一个防火墙问题。 您是否在您的EC2安全组防火墙中打开了端口443? 你在主机的防火墙中打开过吗?


更新;

您的DNS设置不正确

 dig +short theaudioserver.com 52.25.39.220 

而你说你可以通过52 24 .39.220连接。

在您网站的根目录中使用.htaccess文件,将非安全端口上的请求redirect到安全端口,即http:// – > https://

该文件应该包含这样的东西:

 RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] 

您需要在sites-available编辑default sites-available来包含:

 DocumentRoot /var/www/html <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/html> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> 

这允许.htaccess工作在该目录和所有包含的目录,因此您的整个网站。