NGINX - Статическое содержимое обратного прокси в HTTP/2

У меня есть приложение node.js, которое обслуживается через proxy_pass в NGINX и я включил HTTP/2. Конечно, обратные вызовы в HTTP/1.1, и я добавил блок для обслуживания статических ресурсов напрямую без обратного прокси-сервера, поэтому они должны быть в HTTP/2, но это не так.

Это мой код:

# Expires map
map $sent_http_content_type $expires {
    default                    off;
    text/html                  epoch;
    text/css                   max;
    application/javascript     max;
    ~image/                    max;
}

# The upstream module is the link between Node.js and Nginx.
upstream balance {
  # Set up multiple Node.js webservers for load balancing.
  server 127.0.0.1:3333 max_fails=0 fail_timeout=10s weight=1;

  # Send visitors back to the same server each time.
  ip_hash;

  # Enable number of keep-alive connections.
  keepalive 512;
}

server {
  listen 443 ssl http2 default_server; # managed by Certbot
  listen [::]:443 ssl http2 ipv6only=on default_server; # managed by Certbot

  ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; # managed by Certbot
  include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

  server_name mysite.com www.mysite.com;

  expires $expires;

  # Set cookie size
  large_client_header_buffers 4 64k;
  fastcgi_buffers 16 64k;
  fastcgi_buffer_size 64k;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;

  # Serve static files without going through upstreams
  location ~ ^/(assets/images/|assets/js/|assets/css/|static/|robots.txt|humans.txt|favicon.ico) {
    root /var/www/project/public;
    access_log off;
    expires max;
  }

  location / {
    # Set this to your upstream module.
    proxy_pass http://balance;

    # Headers to pass to proxy server.
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto-Version $http2;
    proxy_set_header Host $host;
    proxy_set_header X-NginX-Proxy true;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_cache_bypass $http_upgrade;
    proxy_http_version 1.1;
    proxy_redirect off;
    # Go to next upstream after if server down.
    proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
    proxy_connect_timeout 5s;
    # Gateway timeout.
    proxy_read_timeout 20s;
    proxy_send_timeout 20s;
    # Buffer settings.
    proxy_buffers 8 32k;
    proxy_buffer_size 64k;
  }
}

Блок относительно статических ресурсов работает правильно, но все вызовы через этот блок всегда HTTP/1.1, а не HTTP/2:

пример http1

Есть идеи о причине?

Это вывод nginx -V, он содержит флаг --with-http_v2_module,

nginx version: nginx/1.10.3 (Ubuntu)
built with OpenSSL 1.0.2g  1 Mar 2016
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads

0 ответов

Другие вопросы по тегам