sciblog
sciblog copied to clipboard
Use HTTP2 for all resources
| Use HTTP/2 for all resources | Potential savings of 1.6s |
https://miguelgfierro.com/ | http/1.1 | https://miguelgfierro.com/static/blog/css/popup.min.css | http/1.1 https://miguelgfierro.com/static/blog/css/skeleton.min.css | http/1.1 https://miguelgfierro.com/static/blog/css/paper.min.css | http/1.1 https://miguelgfierro.com/static/blog/js/jquery.min.js | http/1.1 https://miguelgfierro.com/static/blog/js/popup.min.js | http/1.1 https://miguelgfierro.com/static/blog/img/hoap_front_small.png | http/1.1 https://miguelgfierro.com/static/blog/img/icon_search.png | http/1.1 https://miguelgfierro.com/static/blog/img/sprites_social_square.png | http/1.1 https://miguelgfierro.com/static/blog/font/cmunrm.woff | http/1.1 https://miguelgfierro.com/static/blog/img/favicon.ico | http/1.1 https://miguelgfierro.com/static/blog/img/apple-touch-icon.png | http/1.1 https://miguelgfierro.com/static/blog/font/cmunbx.woff | http/1.1
According to https://httpd.apache.org/docs/2.4/howto/http2.html, I tried
When you have a httpd built with mod_http2 you need some basic configuration for it becoming active. The first thing, as with every Apache module, is that you need to load it:
LoadModule http2_module modules/mod_http2.so
The second directive you need to add to your server configuration is
Protocols h2 http/1.1
This allows h2, the secure variant, to be the preferred protocol on your server connections. When you want to enable all HTTP/2 variants, you simply write:
Protocols h2 h2c http/1.1
but it didn´t work
$ apache2 -V
[Mon Jul 25 17:49:35.274383 2022] [core:warn] [pid 24006] AH00111: Config variable ${APACHE_RUN_DIR} is not defined
apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot
Server version: Apache/2.4.46 (Ubuntu)
Server built: 2021-03-13T15:08:08
Server's Module Magic Number: 20120211:93
Server loaded: APR 1.7.0, APR-UTIL 1.6.1
Compiled using: APR 1.7.0, APR-UTIL 1.6.1
Architecture: 64-bit
Server MPM:
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_PROC_PTHREAD_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/etc/apache2"
-D SUEXEC_BIN="/usr/lib/apache2/suexec"
-D DEFAULT_PIDLOG="/var/run/apache2.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="mime.types"
-D SERVER_CONFIG_FILE="apache2.conf"
Based on https://stackoverflow.com/questions/60345482/apache-http2-h2c-mode-not-working-properly, I tried:
LoadModule http2_module /usr/lib/apache2/modules/mod_http2.so
<IfModule http2_module>
Protocols h2 h2c http/1.1
</IfModule>
Tried H2Direct on
but it didn't work
It seems apache is configured with prefork:
$ cs mods-enabled/
. alias.load authz_core.load autoindex.load dir.load headers.load mime.load negotiation.load setenvif.conf ssl.load wsgi.load
.. auth_basic.load authz_host.load deflate.conf env.load http2.conf mpm_prefork.conf php7.0.conf setenvif.load status.conf
access_compat.load authn_core.load authz_user.load deflate.load expires.load http2.load mpm_prefork.load php7.0.load socache_shmcb.load status.load
alias.conf authn_file.load autoindex.conf dir.conf filter.load mime.conf negotiation.conf rewrite.load ssl.conf wsgi.conf
(base) ubuntu@vps-6c61a433:/etc/apache2/mods-enabled$ cat http2.conf
# mod_http2 doesn't work with mpm_prefork
<IfModule !mpm_prefork>
Protocols h2 h2c http/1.1
# # HTTP/2 push configuration
#
# H2Push on
#
# # Default Priority Rule
#
# H2PushPriority * After 16
#
# # More complex ruleset:
#
# H2PushPriority * after
# H2PushPriority text/css before
# H2PushPriority image/jpeg after 32
# H2PushPriority image/png after 32
# H2PushPriority application/javascript interleaved
#
# # Configure some stylesheet and script to be pushed by the webserver
#
# <FilesMatch "\.html$">
# Header add Link "</style.css>; rel=preload; as=style"
# Header add Link "</script.js>; rel=preload; as=script"
# </FilesMatch>
# Since mod_http2 doesn't support the mod_logio module (which provide the %O format),
# you may want to change your LogFormat directive as follow:
#
# LogFormat "%v:%p %h %l %u %t \"%r\" %>s %B \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
# LogFormat "%h %l %u %t \"%r\" %>s %B \"%{Referer}i\" \"%{User-Agent}i\"" combined
# LogFormat "%h %l %u %t \"%r\" %>s %B" common
</IfModule>
but mod_http2 doesn't work with mpm_prefork
See https://stackoverflow.com/questions/54720116/http-2-configuration-not-running-after-mod-http2-enabled-and-protocols-set-in-co
Tried to enable mpm_event:
$ sudo a2dismod mpm_prefork
Module mpm_prefork disabled.
To activate the new configuration, you need to run:
systemctl restart apache2
$ sudo a2enmod mpm_event
Considering conflict mpm_worker for mpm_event:
Considering conflict mpm_prefork for mpm_event:
Enabling module mpm_event.
To activate the new configuration, you need to run:
systemctl restart apache2
$ sudo systemctl restart apache2
Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.
$ sudo systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2022-07-25 18:12:38 UTC; 20s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 25017 ExecStop=/usr/sbin/apachectl graceful-stop (code=exited, status=1/FAILURE)
Process: 18463 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
Process: 25027 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
Main PID: 24537 (code=exited, status=0/SUCCESS)
Jul 25 18:12:38 vps-6c61a433 systemd[1]: apache2.service: Failed with result 'exit-code'.
Jul 25 18:12:38 vps-6c61a433 systemd[1]: Starting The Apache HTTP Server...
Jul 25 18:12:38 vps-6c61a433 apachectl[25027]: [Mon Jul 25 18:12:38.382715 2022] [:crit] [pid 25034:tid 140495887292288] Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsaf
Jul 25 18:12:38 vps-6c61a433 apachectl[25027]: AH00013: Pre-configuration failed
Jul 25 18:12:38 vps-6c61a433 apachectl[25027]: Action 'start' failed.
Jul 25 18:12:38 vps-6c61a433 apachectl[25027]: The Apache error log may have more information.
Jul 25 18:12:38 vps-6c61a433 systemd[1]: apache2.service: Control process exited, code=exited status=1
Jul 25 18:12:38 vps-6c61a433 systemd[1]: Failed to start The Apache HTTP Server.
Jul 25 18:12:38 vps-6c61a433 systemd[1]: apache2.service: Unit entered failed state.
Jul 25 18:12:38 vps-6c61a433 systemd[1]: apache2.service: Failed with result 'exit-code'.
MPM prefork vs worker vs event: https://serverfault.com/questions/383526/how-do-i-select-which-apache-mpm-to-use/383634#383634