How to enable Nginx HTTP/2 protocol support on Ubuntu and CentOS

Source: Internet
Author: User
Tags centos vps vps ssl certificate root access ubuntu vps

HTTP/2 is a major revision of the HTTP network protocol, which focuses on the performance improvements of the HTTP protocol. The goal of the HTTP/2 protocol is to reduce latency and allow multiple requests to be initiated in parallel on a connection between the Web browser and the server, so that the Web application is faster. In this tutorial, we'll show you how to use the HTTP/2 protocol on a Linux VPS that installs Ubuntu or CentOS as an operating system. If you use Apache, you can check out one of our other tutorials: How to open Apache's HTTP/2 protocol on Ubuntu [1].

Required conditions

In order to be able to finally enable the HTTP/2 protocol on the server in accordance with this tutorial, you need to install Nginx first. and ensure that it is functional and configured without errors. You can use the following command to check:

sudo nginx -t

In addition, you need to have root access to the server, or at least one non-root system user with sudo permissions, so that you do not have permission problems when you modify the Nginx configuration file. Finally you need to have a domain name and a valid SSL certificate issued to this domain name.

Open Nginx's HTTP/2 protocol on Ubuntu

In order to open the Nginx HTTP/2 protocol on the Ubuntu VPS, you need to edit the default Nginx service ( server ) block, which we use nano , you can use your own text editor.

sudo nano /etc/nginx/sites-available/default

Add the following service block:

server {          server_name domain.com www.domain.com;        listen 443 ssl http2 default_server;        root /var/www/html;        index index.html;        location / {                try_files $uri $uri/ =404;        }        ssl_certificate /etc/nginx/ssl/domain.com.crt;        ssl_certificate_key /etc/nginx/ssl/domain.com.key;}server {       listen         80;       server_name    domain.com www.domain.com;       return         301 https://$server_name$request_uri;}

Make sure domain.com to replace your real domain name. In addition, the document root () directory should be set correctly root , as well as the path to the SSL certificate and key.

After you edit the service block, you need to save and close the file. Use the following command to check for an error in the Nginx configuration:

sudo nginx -t

For the change to take effect, you need to restart Nginx:

sudo systemctl restart nginx.service

If you want to open the HTTP/2 protocol for another domain name, you can see how our blog set up Nginx service blocks on Ubuntu and CentOS [2].

Open Nginx's HTTP/2 protocol on CentOS

In order to open the Nginx HTTP/2 protocol on the CentOS VPS, you need to follow the exact same steps on Ubuntu. The only difference is the location of the Nginx block file. In order to edit the default Nginx service block on CentOS, you need to enter /etc/nginx/conf.d this folder.

# nano /etc/nginx/conf.d/default.conf

Check the configuration again for errors, save and close the file, and then restart the Nginx service using the following command:

# systemctl restart nginx.service

To detect if the Nginx HTTP/2 protocol is successful, you can use some online HTTP/2 detection tools

Read the original

How to enable Nginx HTTP/2 protocol support on Ubuntu and CentOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.