可以通过 IP 访问 Apache,但无法通过 SSL 访问域名

可以通过 IP 访问 Apache,但无法通过 SSL 访问域名

我安装了 OwnCloud,我希望只有 https 可用,而不是 http。所以我安装了 Lets Encrypt,安装得很好。我已经将 apache conf 更改为下面的附件。我在我们的路由器上为端口 443 设置了转发。如果我​​浏览到https://IP它能正常工作,但我收到了 SSL 警告,这是正常的,因为 lets encrypt 从 apache 的 serverName 配置中提取了域。如果我去https://files.domain.org.uk我收到 404。

我可能做错了什么?

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName files.domain.org.uk

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/owncloud

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =files.domain.org.uk
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

答案1

因为您的 Apache 的 VirtualHost 指令仅包含针对 HTTP 请求(端口 80)的指令,所以当您请求 HTTPS(端口 443)资源时,Apache 将查看这些指令,但无法匹配,因为您没有为端口 443 声明一个指令。

更改<VirtualHost *:80><VirtualHost *:443>将告诉 Apache,端口 443 上的任何请求与服务器名称匹配files.domain.org.uk应该在您的 DocumentRoot 中查找用于显示您的网站的脚本。

如果您希望<VirtualHost *:80>能够浏览到http://files.domain.org.uk但收到证书警告,或者保持从 HTTP 重定向到 HTTPS...

相关内容