【问题标题】:Apache2 config not redirecting all requests on port 80 to 443Apache2 配置未将端口 80 上的所有请求重定向到 443
【发布时间】:2017-04-25 14:58:03
【问题描述】:

我在我的网络服务器上配置了 apache2:

Server version: Apache/2.4.18 (Ubuntu)
Server built:   2016-07-14T12:32:26

我正在尝试将我的所有 HTTP 流量重定向到 HTTPS:

<VirtualHost *:80>
    RewriteEngine On
    RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
</VirtualHost>

<VirtualHost *:443>
    ServerName example.com
    ServerAlias www.example.com
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
    ...
</VirtualHost>

我的配置工作正常,但是我遇到了以下问题:

> curl -IL "http://example.com/"

HTTP/1.1 301 Moved Permanently
Date: Tue, 25 Apr 2017 14:44:25 GMT
Server: Apache/2.4.18 (Ubuntu)
Location: https://www.example.com/
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 200 OK
Date: Tue, 25 Apr 2017 14:44:25 GMT
Keep-Alive: timeout=10
Connection: Keep-Alive
Accept-Ranges: bytes
Cache-Control: must-revalidate, max-age=604800
Content-Length: 226
Content-Type: text/html
X-HW: 1493131465.dop004.la2.t,1493131465.cds052.la2.shn,1493131465.dop004.la2.t,1493131465.cds025.la2.c
Last-Modified: Thu, 16 Feb 2017 17:05:44 GMT
Access-Control-Allow-Origin: *
Vary: Accept-Encoding
GEO: US
ETag: "e2-548a8cec41423"
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

> curl -IL "http://www.example.com/"

HTTP/1.1 200 OK
Date: Tue, 25 Apr 2017 14:42:57 GMT
Keep-Alive: timeout=10
Connection: Keep-Alive
Accept-Ranges: bytes
Cache-Control: must-revalidate, max-age=604800
Content-Length: 226
Content-Type: text/html
X-HW: 1493131377.dop006.la2.t,1493131377.cds025.la2.c
Last-Modified: Thu, 16 Feb 2017 17:05:44 GMT
Access-Control-Allow-Origin: *
Vary: Accept-Encoding
GEO: US
ETag: "e2-548a8cec41423"
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

正如您在上面的 cURL 中看到的,我的网络服务器正在将非 www HTTP 流量重定向到 www HTTPS,但是,当我尝试从 www HTTP 到 www HTTPS 的相同重定向时,它失败并在我应该时显示 200获得 301。

在这一点上的任何建议将不胜感激。

【问题讨论】:

    标签: ubuntu curl apache2 url-redirection


    【解决方案1】:

    原来问题出在我的 CDN 上。此后,我进行了适当的政策更改,我的网络服务器重定向现在可以正常工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-20
      • 2019-02-02
      • 1970-01-01
      • 2017-01-29
      • 2017-05-04
      • 1970-01-01
      • 1970-01-01
      • 2010-09-29
      相关资源
      最近更新 更多