我已经使用 Apache 2.4.29 设置了 HTTP/2。
HTTP/2 正在按此处检查运行https://tools.keycdn.com/http2-test。
当我通过 Chrome 或 Firefox 连接到我的网站时,只有部分内容使用 h2。具体来说,静态内容通过 http/1.1 提供,而 api 和 websocket 轮询请求通过 h2 提供。我希望所有内容都通过 h2 提供。
但是我可以使用 curl 通过 h2 检索静态文件
curl -k -v https://example.com/images/example.jpg
这是一个具有重写规则的单页应用程序,我认为这是问题所在,但删除它们也没有帮助。
这是我的网站配置:
<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>
任何帮助是极大的赞赏。