迹忆客 EN >

当前位置:主页 > 学无止境 > 网络 >

HTTP2 教程——如何使用Nginx 配置 HTTP2

作者:迹忆客 最近更新:2023/01/08 浏览次数:

HTTP2 在 2015年就已经正式发布了,现在如果网站还在使用HTTP/1.1 是不是就有点赶不上潮流了。不慌,这里我们就来看一下如何使用Nginx将网站升级为HTTP2。

安装Nginx

感觉这一栏就是多余,即然说的是使用Nginx配置HTTP2,当然肯定是要安装Nginx。而Nginx的安装随便一搜到处都是。所以这里我们不具体说如何安装Nginx。我们只说两个具体的点。

首先是Nginx的版本不能低于Nginx 1.10。然后就是默认编译的 Nginx 并不包含 h2 模块,我们需要加入参数来编译。

$ ./configure --with-http_v2_module
# 然后就是编译安装了
$ make && make install

还有就是HTTP2 要和 HTTPS一起。因此需要openssl的支持。这里的openssl的版本也是有要求的。最低要求1.0.2,如果不满足,还得手动下载openssl,然后在编译时使用–with-openssl指定openssl目录。

配置 Nginx

这里,废话不多说,直接上配置

server {
        listen          443 ssl http2;
        listen          [::]:443 ssl http2;
        server_name     www.jiyik.com jiyik.com;

        ssl_certificate /certificates/www.jiyik.com/fullchain.pem;
        ssl_certificate_key /certificates/www.jiyik.com/privkey.pem;
        ssl_trusted_certificate /certificates/www.jiyik.com/fullchain.pem;

        ssl_session_timeout 1d;
        ssl_session_cache shared:SSL:50m;
        ssl_session_tickets off;

部分配置项就是张的这样,剩余的可以去网补。

检测是否支持HTTP2

上面配置完成之后,重启Nginx。然后再访问我们的网站,可以通过 chrome浏览器的开发者工具查看是否支持HTTP2。

chrom查看是否支持http2

这里推荐一款Chrome的扩展 HTTP/2 and SPDY indicator 可以查看是否支持HTTP2

运行结果如下

迹忆客支持HTTP2 示例

推荐阅读: HTTP2 教程 - HTTP2 的前世今生  与 HTTP2 教程 - HTTP2的功能升级

转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处

本文地址:

相关文章

How to Install Nginx on Ubuntu 20.04?

发布时间:2025/04/07 浏览次数:157 分类:OPERATING SYSTEM

Nginx is one of the most popular web servers in the world, responsible for hosting some of the largest and most trafficked sites on the Internet. It is a lightweight application software that can be used as a web server or a reverse proxy.

Install WordPress with Nginx on Ubuntu 18.04

发布时间:2025/04/07 浏览次数:86 分类:OPERATING SYSTEM

WordPress is one of the most popular open source content management systems (CMS) with a market share of up to 60% compared to other CMS like Drupal or Joomla. WordPress can be used to develop any type of website, be it a blog, a small busi

Solution to incorrect access log time when deploying Nginx in Docker

发布时间:2025/03/26 浏览次数:167 分类:Docker

In the process of operating the website, I never took the logs too seriously. Although logging was turned on, I never analyzed the logs carefully. Today, when I looked at the logs on a whim, I found that the recorded time was 8 hours less t

Docker deploys nginx php application

发布时间:2025/03/26 浏览次数:132 分类:Docker

I'm learning docker recently. I'm learning by building an nginx+php development environment example. Here I record the build process. First, give a docker-compose.yml deployment configuration file version: '3' services: nginx: container_nam

Nginx load balancing settings

发布时间:2025/03/18 浏览次数:198 分类:NETWORK

At this stage, load balancing is a widely used technology. Nginx, as a load balancing server for http, is being used more and more widely. There are three ways to set up Nginx load balancing: Round-robin - This method distributes access req

Nginx load balancing health_check analysis

发布时间:2025/03/18 浏览次数:56 分类:NETWORK

In Nginx load balancing, it is difficult to guarantee that every application server can run normally all the time. However, we can set Nginx to detect these application servers and detect which of them are inaccessible. There are two ways t

HTTP2 Tutorial - The Past and Present of HTTP2

发布时间:2025/03/16 浏览次数:73 分类:NETWORK

HTTP was originally proposed by Timberners-Lee, a pioneer of the World Wide Web, who designed the application protocol with simplicity in mind to perform advanced data communication functions between web servers and clients. The first docum

HTTP2 Tutorial - The shortcomings of HTTP1.1

发布时间:2025/03/16 浏览次数:145 分类:NETWORK

HTTP 1.1 is limited to handling only one outstanding request per TCP connection, forcing browsers to use multiple TCP connections to handle multiple requests simultaneously. However, using too many TCP connections in parallel can cause TCP

扫一扫阅读全部技术教程

社交账号
  • https://www.github.com/onmpw
  • qq:1244347461

最新推荐

教程更新

热门标签

扫码一下
查看教程更方便