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

How to upgrade nginx to support HTTP/2 server push

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "how to upgrade nginx to support HTTP/2 server push". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

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.

This is the end of the content of "how to upgrade nginx to support HTTP/2 server push". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Internet Technology

Wechat

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

12
Report