LoginSignup
9
7

More than 3 years have passed since last update.

Chrome「net::ERR_HTTP2_PROTOCOL_ERROR」 Safari 「kCFErrorDomainCFNetwork」 エラー

Last updated at Posted at 2019-11-15

Nginxでリバプロしているプロダクトにて、APIへのアクセスで以下エラーに遭遇しデータ取得に失敗していた。

・Chromeで Chrome net::ERR_HTTP2_PROTOCOL_ERROR エラー
・Safariで kCFErrorDomainCFNetwork エラー

レスポンスデータのサイズが一定以上になる時に発生しており、
ブラウザのコンソールで確認できるエラー発生時には、
Nginxのエラーログにも以下のようなエラーが確認できた。

2019/11/15 18:05:31 [crit] 7507#7507: *951 open() "/var/lib/nginx/proxy/3/01/0000000013" failed (13: Permission denied) while reading upstream, client: 130.211.2.229, server: xxx.com, request: "GET /api/xxx HTTP/1.1", upstream: "http://unix:xxx.sock:/api/xxx", host: "xxx.com"

原因

以下記事にたどり着いて原因が判明。
大容量ファイルをsend_file / send_dataできない

以下 Nginxドキュメントより

Nginx-proxy_temp_file_write_size
Limits the size of data written to a temporary file at a time, when buffering of responses from the proxied server to temporary files is enabled. By default, size is limited by two buffers set by the proxy_buffer_size and proxy_buffers directives. The maximum size of a temporary file is set by the proxy_max_temp_file_size directive.

Nginxでは一定以上のデータサイズを超えるProxyをする場合は、ローカルファイルにバッファする仕様があり、Nginx実行ユーザがバッファファイル作成領域 /var/lib/nginx/proxy/ に対する書き込み権限がないことが原因で冒頭のエラーが発生していた。

対策

Nginx実行ユーザがバッファファイル作成領域に対して書き込み権限を付与した。

$ ls -l /var/lib/nginx/
total 28
drwxr-xr-x  7 root     root 4096 Sep 19 18:25 ./
drwxr-xr-x 42 root     root 4096 Sep 22 16:52 ../
drwx------  2 nginx root 4096 Nov 12 15:58 body/
drwx------  2 nginx root 4096 Sep 19 18:25 fastcgi/
drwx------ 12 nginx root 4096 Sep 20 01:57 proxy/
drwx------  2 nginx root 4096 Sep 19 18:25 scgi/
drwx------  2 nginx root 4096 Sep 19 18:25 uwsgi/

$ sudo chown -R nginx:nginx /var/lib/nginx
9
7
1

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
9
7