0

I have setup HTTP/2 with Apache 2.4.29.

HTTP/2 is working as checked here https://tools.keycdn.com/http2-test.

When I connect to my site via Chrome or Firefox only some content is using h2. Specifically static content is served via http/1.1 while api and websocket polling requests are served via h2. I'd like everything to be served via h2.

However, I can retrieve static files via h2 with curl

curl -k -v https://example.com/images/example.jpg

This is a single-page app with rewrite rules which I thought were the problem but removing them does not help.

Here is my site config:

<IfModule mod_ssl.c>
<VirtualHost *:443>
  Protocols h2 http/1.1
  ServerName example.com
  DocumentRoot /home/ubuntu/public_html

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  # socket.io 1.0+ starts all connections with an HTTP polling request
  RewriteCond %{QUERY_STRING} transport=polling       [NC]
  RewriteRule /(.*)           http://localhost:8004/$1 [P]

  # When socket.io wants to initiate a WebSocket connection, it sends an
  # "upgrade: websocket" request that should be transferred to ws://
  RewriteCond %{HTTP:Upgrade} websocket               [NC]
  RewriteRule /(.*)           ws://localhost:8004/$1  [P]

  # Proxy API
  ProxyRequests Off
  ProxyPreserveHost On
  ProxyVia Full
  ProxyPass /api http://localhost:8004
  ProxyPassReverse /api http://localhost:8004

  <Directory "/home/ubuntu/public_html" >
    # Don't rewrite files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Rewrite everything else to index.html to allow html5 state links
    RewriteRule ^ index.html [L]
  </Directory>

  # Certs
  SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
  Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Any help is greatly appreciated.

  • 1
    I would guess they were cached under HTTP/1 and so are reporting that. Clear you cache and try again. – Barry Pollard Nov 20 '18 at 20:33
  • Disabling cache in Chrome developer tools worked. Thank you. I had done "Empty cache and hard reload" but that didn't work. I was also testing my site at web.dev and it's reporting requests served via http1.1, but I gather it's working from its own cached files. – James Nov 20 '18 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.