nginx是否支持早期提示请求(103状态)

时间:2018-05-30 18:21:28

标签: ruby-on-rails nginx puma

我使用nginx作为puma服务器的反向代理。

我发送了来自美洲狮的103状态回复,以提前暗示需要的资产。

当我在chrome中加载页面时,它显示ERR_SPDY_PROTOCOL_ERROR错误。 它适用于Firefox。也没有在野生动物园工作。

只有当我停止从美洲狮发送103状态响应时,它在chrome中才能正常工作。

下面是我的nginx.config文件

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;
 }
}

以下是nghttp客户端的输出

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

nginx是否支持早期提示?我无法获得任何文档声明它支持它。但是我支持它,因为它支持HTTP / 2.

2 个答案:

答案 0 :(得分:0)

来自讨论https://github.com/puma/puma/issues/1570

如果您需要服务器实现早期提示,则可以使用https://h2o.examp1e.net

我还没有使用它,但是一旦一切正常,H2O的效果非常好并且生产就绪。

答案 1 :(得分:0)

如果您想使用early_hints_header

,也可以使用Nginx's http2_push_preload functionality gem