虚拟主机域名注册-常见问题 → 服务器知识 → 操作系统 | ||||
先决条件: 使用ngx_http_v2_module模块构建的NGINX 1.9.5或更高版本的有效安装。 确保您的网站使用SSL/TLS证书,如果您没有SSL/TLS证书,则可以从各大云服务商获取或使用自签名证书。 如何在NGINX中启用HTTP/2.0 如果已安装NGINX,请ngx_http_v2_module通过运行以下命令来验证它是否是由模块构建的。 # strings /usr/sbin/nginx | grep _module | grep -v configure| sort | grep ngx_http_v2_module ![]() 检查Nginx HTTP / 2模块 Nginx通过配置了HTTPS的网站/应用程序提供服务后,打开您的网站虚拟服务器配置文件(或虚拟主机)文件进行编辑。 # vi /etc/nginx/conf.d/example.com.conf [On CentOS/RHEL] $ sudo nano /etc/nginx/sites-available/example.com.conf [On Ubuntu/Debian] 您只需将http2参数添加到所有listen指令即可启用HTTP/2支持,如以下屏幕截图所示。 listen 443 ssl http2; 示例服务器配置文件配置如下所示。 server { server_name example.com www.example.com; access_log /var/log/nginx/example.com_access.log; error_log /var/log/nginx/example.com_error.log; listen [::]:443 ssl ipv6only=on http2; # managed by Certbot listen 443 ssl http2; # managed by Certbot ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } ![]() 在Nginx中启用HTTP / 2支持 将更改保存在文件中并关闭。 然后检查NGINX的配置语法,如果可以,请重新启动Nginx服务。 # nginx -t # systemctl restart nginx 接下来,打开一个Web浏览器以验证您的网站是否通过HTTP/2进行服务。 http://你的域名。 要访问HTTP标头,请在显示的网页上单击鼠标右键,从选项列表中选择“ 检查 ”以打开开发人员工具,然后单击“ 网络”选项卡,然后重新加载页面。 在“协议”下检查以查看您的站点正在使用的协议(如果没有看到“协议”标头,请右键单击任何标头,例如Name,然后从列表中检查“协议”以将其显示为标头)。 如果您的站点在HTTP/1.1上运行,在Protocol下,您将看到http/1.1,如以下屏幕截图所示。 ![]() 在HTTP / 1.1上运行的网站 如果它在HTTP/2上运行,则在Protocol下,您将看到h2以下屏幕截图所示。您可能要禁用浏览器缓存,以查看直接从Web服务器提供的最新内容。 ![]() 在HTTP / 2.0上运行的网站
|
||||
>> 相关文章 | ||||