The method of upgrading nginx to support HTTP/2 server push
Content overview
NGINX has supported HTTP/2 server push since version 1.13.9, and last week found time to upgrade NGINX to try out new features on blogs.
The upgrade work mainly includes:
Upgrade NGINX modify NGINX configuration modify wordpress theme
Upgrade NGINX to 1.14.0
1. Configure the official yum source of nginx. Create a configuration file / etc/yum.repos.d/nginx.repo and write the following
[nginx] name=nginx repobaseurl= http://nginx.org/packages/centos/7/$basearch/gpgcheck=0enabled=1
2. Update nginx
Yum update
3. Restart nginx
Systemctl restart nginx
4. Verify the nginx version
$curl-I 127.0.0.1HTTP/1.1 301 Moved PermanentlyServer: nginx/1.14.0
Modify NGINX configuration
Add http2_push_preload on; to the original configuration. When nginx detects the link response header, it actively pushes the resource to the client.
Location. Php$ {#... Omit other configurations http2_push_preload on; # plus this line}
Modify WordPress theme
The http2_push_preload of NGINX requires the cooperation of application services. For example, if I want to push the index.js file actively, I need to add the following response header:
Link:; as=script; rel=preload
You can also push multiple files at the same time, such as:
Link:; as=script; rel=preload,; as=style; rel=preload
For WordPress, you can add the following code:
Function add_http2_push_header () {$preload_resource_array = array ('; as=script; rel=preload','; as=style; rel=preload'); $preload_link_value = join (',', $preload_resource_array); header ('link:'. $preload_link_value);} add_action ('send_headers',' add_http2_push_header')
Browser verification
Server push is not supported before upgrading.
After the upgrade, server push is supported.
Related links
Https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#prebuilt_redhat
Https://www.nginx.com/blog/nginx-1-13-9-http2-server-push/
Http://nginx.org/en/docs/http/ngx_http_v2_module.html#http2_push_preload
Https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.