【问题标题】:Enabling SSL for Vhost on Ubuntu 14.04 / Apache2在 Ubuntu 14.04 / Apache2 上为 Vhost 启用 SSL
【发布时间】:2017-07-22 00:06:22
【问题描述】:

我正在尝试在我的 Ubuntu 服务器上的网站上启用 SSL。我在互联网上到处都找到了几乎相同的几个命令,看起来很简单,但由于某种原因,我似乎无法正确处理。

这是我的步骤(所有步骤都以 root/sudo 权限完成)

启用 SSL 模块

a2enmod ssl

为我的密钥创建一个 Apache 和用户/站点所有者有权访问的控制器

sudo mkdir /etc/apache2/ssl

使用它们所属域的详细名称制作所需的密钥

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
      -keyout /etc/apache2/ssl/example.key -out /etc/apache2/ssl/example.crt

我有一个为此网站制作的现有 .conf 文件,如下所示:

(而且我的 /home 目录也设置为 web 目录)

<VirtualHost *:80>
       DocumentRoot /home/user
       <Directory /home/user>
               AllowOverride All
       </Directory>
       ServerName example.com
       ServerAlias www.example.com
       ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
       CustomLog ${APACHE_LOG_DIR}/example.com.access.log common
       AddType application/x-httpd-php .php
       <Files 'xmlrpc.php'>
               Order Allow,Deny
               deny from all
       </Files>
</VirtualHost>

我尝试使用以下 .conf 文件添加、替换、放置之前/之后,但无法使 https://example.com 工作。 (我添加的附加行来自此处找到的数字海洋教程:https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-14-04

<IfModule mod_ssl.c>
    <VirtualHost *:443>
           DocumentRoot /home/user
           <Directory /home/user>
                   AllowOverride All
           </Directory>
           ServerName example.com
           ServerAlias www.example.com

            SSLEngine on
            SSLCertificateFile /etc/apache2/ssl/example.crt
            SSLCertificateKeyFile /etc/apache2/ssl/example.key
            <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
            </FilesMatch>
            <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
            </Directory>
            BrowserMatch "MSIE [2-6]" \
                    nokeepalive ssl-unclean-shutdown \
                    downgrade-1.0 force-response-1.0
            BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

           ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
           CustomLog ${APACHE_LOG_DIR}/example.com.access.log common
           AddType application/x-httpd-php .php
           <Files 'xmlrpc.php'>
                   Order Allow,Deny
                   deny from all
           </Files>
    </VirtualHost>
</IfModule>    

该站点之前已启用,因此我不必运行 a2ensite 命令,尽管我确实确保该站点已启用。然后我重新启动了apache

service apache2 restart

然后转到https://example.com,我的 SSL 没有运气。

我意识到我正在遵循的教程正在更新默认的 apache 文件,并且我正在尝试创建另一个虚拟主机,所以它有点不同,但我只是创建了一个额外的虚拟主机,我想它会工作与添加额外的 .conf 文件完全相同。

该网站在没有 SSL 的情况下运行良好,因此我的 apache 配置将成为这里的罪魁祸首是有道理的,我似乎无法弄清楚我到底在哪里犯了错误。任何帮助将不胜感激,谢谢!

【问题讨论】:

  • 我假设您在配置中的其他地方有一个Listen 443 和可能的NameVirtualHost *:443? (另外,什么是“你的 SSL 不走运”?它是否抱怨证书,它根本没有给你任何连接?)
  • 服务器日志有什么线索吗?

标签: apache ssl


【解决方案1】:

假设您发布的代码来自 default-ssl.conf,试试这个:

a2dissite default-ssl.conf

然后

a2ensite default-ssl.conf

然后

service apache2 reload

【讨论】:

    【解决方案2】:

    我不知道证书是自签名的,我必须在我的浏览器中授权证书。

    有一个很棒的工具可以为您处理所有 SSL 配置,我强烈推荐 - 看看吧!

    https://certbot.eff.org/

    【讨论】:

      猜你喜欢
      • 2015-11-20
      • 2015-06-20
      • 1970-01-01
      • 2014-08-14
      • 2018-01-27
      • 1970-01-01
      • 1970-01-01
      • 2014-06-21
      • 1970-01-01
      相关资源
      最近更新 更多