LoginSignup
10

More than 5 years have passed since last update.

apacheでHTTP206を抑制する方法

発生した障害

SprintBootにて、apacheプロキシを経由し、以下で公開したpdfファイルがIE11で正常に開けない。
→apacheでHTTP Status 206(Partial Content)で返戻している場合は、「カラースペースが無効です。」エラーが発生する。
→apacheでHTTP Status 200で返戻している場合は、同一ファイルでも正常に開くことができる。

WebConfig.java
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
    @Bean
    public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
        return new ResourceUrlEncodingFilter();
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
    }
}

HTTP Status 206(Partial Content)が返戻される条件

RFC7233よりRange(If-Range)要請があった場合、206が応答されるよう

設定内容(httpd.conf)

以下を追加 ※本番適応時は、必要に応じFileディレクティブ等で適応範囲を絞ること

  • 最低限の設定
httpd.conf
RequestHeader unset Range
  • Example
httpd.conf
<Files *.pdf>
    Header set Accept-Ranges none #クライアントへRangeアクセスは受け付けないよという応答
    RequestHeader unset Range #Rangeアクセスを強制的に解除
</Files>

 検証

  • 検証に利用したファイル
index.html
[ec2-user@ip-172-31-1-128 ~]$ cat /var/www/html/index.html
01234567890123456789
  • 設定なし
[ec2-user@ip-172-31-1-128 ~]$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
HEAD / HTTP/1.1
Host: localhost
Range: bytes=0-10

HTTP/1.1 206 Partial Content
Date: Tue, 28 Feb 2017 01:26:57 GMT
Server: Apache/2.2.31 (Amazon)
Last-Modified: Tue, 28 Feb 2017 00:41:57 GMT
ETag: "606b7-15-5498c769f64c3"
Accept-Ranges: bytes
Content-Length: 11
Content-Range: bytes 0-10/21
Connection: close
Content-Type: text/html; charset=UTF-8

Connection closed by foreign host.
  • 設定あり
[ec2-user@ip-172-31-1-128 ~]$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
HEAD / HTTP/1.1
Host: localhost
Range: bytes=0-10

HTTP/1.1 200 OK
Date: Tue, 28 Feb 2017 01:27:28 GMT
Server: Apache/2.2.31 (Amazon)
Last-Modified: Tue, 28 Feb 2017 00:41:57 GMT
ETag: "606b7-15-5498c769f64c3"
Accept-Ranges: none
Content-Length: 21
Connection: close
Content-Type: text/html; charset=UTF-8

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10