简体   繁体   中英

Does nginx support early hint request (103 status)

I have used nginx as a reverse proxy with puma server.

I am sending 103 status response from the puma for early hint about assets that would be needed.

When I load the page in chrome, it shows me ERR_SPDY_PROTOCOL_ERROR error. It works fine on Firefox. Not working on safari as well.

It works fine in chrome only if I stop sending 103 status response from puma.

Below is my nginx.config file

http {
upstream app {
    server unix:/Users/rohan/puma.sock fail_timeout=0;
}

server {
    listen 443 ssl http2;
    server_name localhost;

    ssl_certificate /usr/Users/rohan/localhost.crt;
    ssl_certificate_key /Users/rohan/localhost.key;
    root /Users/rohan/test_app/my_app/public;

    try_files $uri/index.html $uri @app;
    access_log /Users/rohan/nginx.access.log;


    location @app {
        proxy_pass http://app;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        http2_push_preload on;
    }

    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
 }
}

Below is output from nghttp client

Rohans-MacBook: rohan$ nghttp -nv https://127.0.0.1/students
[  0.010] Connected
[WARNING] Certificate verification failed: Hostname mismatch
The negotiated protocol: h2
[  0.013] recv SETTINGS frame <length=18, flags=0x00, stream_id=0>
          (niv=3)
          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):128]
          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65536]
          [SETTINGS_MAX_FRAME_SIZE(0x05):16777215]
[  0.013] recv WINDOW_UPDATE frame <length=4, flags=0x00, stream_id=0>
          (window_size_increment=2147418112)
[  0.013] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
          (niv=2)
          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
[  0.013] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
[  0.013] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
          (dep_stream_id=0, weight=201, exclusive=0)
[  0.013] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
          (dep_stream_id=0, weight=101, exclusive=0)
[  0.013] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
          (dep_stream_id=0, weight=1, exclusive=0)
[  0.013] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
          (dep_stream_id=7, weight=1, exclusive=0)
[  0.013] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
          (dep_stream_id=3, weight=1, exclusive=0)
[  0.013] send HEADERS frame <length=43, flags=0x25, stream_id=13>
          ; END_STREAM | END_HEADERS | PRIORITY
          (padlen=0, dep_stream_id=11, weight=16, exclusive=0)
          ; Open new stream
          :method: GET
          :path: /students
          :scheme: https
          :authority: 127.0.0.1
          accept: */*
          accept-encoding: gzip, deflate
          user-agent: nghttp2/1.32.0
[  0.014] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
[  0.071] recv (stream_id=13) :method: GET
[  0.071] recv (stream_id=13) :path: /assets/application.self-f0d704deea029cf000697e2c0181ec173a1b474645466ed843eb5ee7bb215794.css
[  0.071] recv (stream_id=13) :scheme: https
[  0.071] recv (stream_id=13) :authority: 127.0.0.1
[  0.071] recv (stream_id=13) accept-encoding: gzip, deflate
[  0.071] recv (stream_id=13) user-agent: nghttp2/1.32.0
[  0.071] recv PUSH_PROMISE frame <length=106, flags=0x04, stream_id=13>
          ; END_HEADERS
          (padlen=0, promised_stream_id=2)
[  0.071] recv (stream_id=13) :status: 103
[  0.071] recv (stream_id=13) server: nginx/1.13.12
[  0.071] recv (stream_id=13) date: Wed, 30 May 2018 18:15:58 GMT
[  0.071] recv (stream_id=13) link: </assets/application.self-f0d704deea029cf000697e2c0181ec173a1b474645466ed843eb5ee7bb215794.css>; rel=preload; as=style
[  0.071] recv HEADERS frame <length=132, flags=0x04, stream_id=13>
          ; END_HEADERS
          (padlen=0)
          ; First response header
[  0.071] recv (stream_id=2) :status: 200
[  0.071] recv (stream_id=2) server: nginx/1.13.12
[  0.071] recv (stream_id=2) date: Wed, 30 May 2018 18:15:58 GMT
[  0.071] recv (stream_id=2) content-type: text/css; charset=utf-8
[  0.071] recv (stream_id=2) content-length: 676
[  0.071] recv (stream_id=2) cache-control: public, max-age=31536000
[  0.071] recv (stream_id=2) etag: "f0d704deea029cf000697e2c0181ec173a1b474645466ed843eb5ee7bb215794"
[  0.071] recv (stream_id=2) x-request-id: a7bd5757-b7ab-4d7a-9c48-10b5133fe11e
[  0.071] recv (stream_id=2) x-runtime: 0.010249
[  0.071] recv HEADERS frame <length=198, flags=0x04, stream_id=2>
          ; END_HEADERS
          (padlen=0)
          ; First push response header
[  0.071] recv DATA frame <length=676, flags=0x01, stream_id=2>
          ; END_STREAM
[  0.080] send RST_STREAM frame <length=4, flags=0x00, stream_id=13>
          (error_code=PROTOCOL_ERROR(0x01))
[  0.080] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
          (last_stream_id=2, error_code=NO_ERROR(0x00), opaque_data(0)=[])
Some requests were not processed. total=2, processed=1

Is Early hint supported by nginx? I am not able to get any documentation stating that it supports it. But I assummed it as it supports HTTP/2.

From the discussion https://github.com/puma/puma/issues/1570

If you need a server implementing early hints, you can use https://h2o.examp1e.net

I'm yet to use it but H2O works quite good and production ready once everything is working.

如果你想使用Nginx 的 http2_push_preload 功能,你也可以使用early_hints_header gem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM