Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of upgrading nginx to support HTTP/2 server push

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report