Home Web Front-end H5 Tutorial Teach you step by step how to enable https and http2 for your site (with code)

Teach you step by step how to enable https and http2 for your site (with code)

Sep 01, 2021 am 11:09 AM
h5 http front end

In the previous article "A brief analysis of the installation and use of nginx (Collection)", I introduced you to the installation and use of nginx. The following article will introduce to you how to enable https and http2 for the site. Let's see how to do it together.

Teach you step by step how to enable https and http2 for your site (with code)

This article mainly introduces how to enable https and http2

# for the site Teach you step by step how to enable https and http2 for your site (with code)

##This article mainly introduces how to enable

https and http2

to enable

https for the site. Simply take this site Linux nginx as an example

3 commands to

download the script

1

2

wget https://dl.eff.org/certbot-auto

chmod a+x certbot-auto

Copy after login

automatically associate to

nginx

1

2

3

4

$sudo ./certbot-auto --nginx

```sh

 

## 检查证书有没有过期

Copy after login

$sudo ./certbot-auto renew --dry-run

1

2

3

4

## 如果过期了就自动续订

 

```sh

$sudo ./certbot-auto renew

Copy after login

If the following error code is prompted

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128) is because the configuration file of nginx contains Chinese characters, so change the Chinese to English That’s it

Or you can search it by yourself

1

grep -r -P '[^\x00-\x7f]' /etc/nginx /etc/letsencrypt

Copy after login

Okay, now open

nginxConfiguration and take a look

1

2

3

4

5

6

7

8

9

10

11

12

listen 443 ssl http2;

ssl on;

ssl_certificate /etc/letsencrypt/live/chuchur.com/fullchain.pem;

ssl_certificate_key /etc/letsencrypt/live/chuchur.com/privkey.pem;

include /etc/letsencrypt/options-ssl-nginx.conf;

ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

 

if ($scheme != "https") {

 

    return 301 https://$host$request_uri;

 

} # managed by Certbot

Copy after login

Note that the nginx version is too low If it cannot be opened, you must first upgrade the nginx version, taking centos as an example

Modify the nginx of

/etc/yum.repos.d/nginx.repoWarehouse address

1

2

3

4

5

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/

gpgcheck=0

enabled=1

Copy after login

If nginx has not been installed, directly execute yum install nginx. If it has been installed, you can upgrade it through yum clean all && yum update nginx.

It is recommended to stop

nginxViolent stopkillall nginx, then uninstall yum remove nginx and then reinstall yum install nginx

Ubuntu/Debian upgrade HTTP/2

First modify

aptwarehouse source/etc/apt/ For the address of source.list, add the following two lines of warehouse.

1

2

deb http://nginx.org/packages/mainline/debian/ codename nginx

deb-src http://nginx.org/packages/mainline/debian/ codename nginx

Copy after login

Next execute

1

apt-get clean && apt-get install nginx

Copy after login

Okay, now the

https is successfully opened, 443 ssl The one behind http2, that is, it is turned on http2

Finally restart nginx

1

nginx -s reload

Copy after login
Refresh the page and find a lock in front of the URL, which means

https is successfully opened

How to verify that

http2 is turned on? Open the URL to be verified and wait until it is loaded. Then open a new tab and enter chrome://net-internals /#http2Enter

If you find the IP corresponding to your URL in the list, it seems that it has been successfully opened.

Of course, use Google Chrome

[End]

Recommended learning:

http video tutorial

The above is the detailed content of Teach you step by step how to enable https and http2 for your site (with code). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1656
14
PHP Tutorial
1257
29
C# Tutorial
1229
24
Understand common application scenarios of web page redirection and understand the HTTP 301 status code Understand common application scenarios of web page redirection and understand the HTTP 301 status code Feb 18, 2024 pm 08:41 PM

Understand the meaning of HTTP 301 status code: common application scenarios of web page redirection. With the rapid development of the Internet, people's requirements for web page interaction are becoming higher and higher. In the field of web design, web page redirection is a common and important technology, implemented through the HTTP 301 status code. This article will explore the meaning of HTTP 301 status code and common application scenarios in web page redirection. HTTP301 status code refers to permanent redirect (PermanentRedirect). When the server receives the client's

PHP and Vue: a perfect pairing of front-end development tools PHP and Vue: a perfect pairing of front-end development tools Mar 16, 2024 pm 12:09 PM

PHP and Vue: a perfect pairing of front-end development tools. In today's era of rapid development of the Internet, front-end development has become increasingly important. As users have higher and higher requirements for the experience of websites and applications, front-end developers need to use more efficient and flexible tools to create responsive and interactive interfaces. As two important technologies in the field of front-end development, PHP and Vue.js can be regarded as perfect tools when paired together. This article will explore the combination of PHP and Vue, as well as detailed code examples to help readers better understand and apply these two

Exploring Go language front-end technology: a new vision for front-end development Exploring Go language front-end technology: a new vision for front-end development Mar 28, 2024 pm 01:06 PM

As a fast and efficient programming language, Go language is widely popular in the field of back-end development. However, few people associate Go language with front-end development. In fact, using Go language for front-end development can not only improve efficiency, but also bring new horizons to developers. This article will explore the possibility of using the Go language for front-end development and provide specific code examples to help readers better understand this area. In traditional front-end development, JavaScript, HTML, and CSS are often used to build user interfaces

How to implement HTTP streaming using C++? How to implement HTTP streaming using C++? May 31, 2024 am 11:06 AM

How to implement HTTP streaming in C++? Create an SSL stream socket using Boost.Asio and the asiohttps client library. Connect to the server and send an HTTP request. Receive HTTP response headers and print them. Receives the HTTP response body and prints it.

Questions frequently asked by front-end interviewers Questions frequently asked by front-end interviewers Mar 19, 2024 pm 02:24 PM

In front-end development interviews, common questions cover a wide range of topics, including HTML/CSS basics, JavaScript basics, frameworks and libraries, project experience, algorithms and data structures, performance optimization, cross-domain requests, front-end engineering, design patterns, and new technologies and trends. . Interviewer questions are designed to assess the candidate's technical skills, project experience, and understanding of industry trends. Therefore, candidates should be fully prepared in these areas to demonstrate their abilities and expertise.

What status code is returned for an HTTP request timeout? What status code is returned for an HTTP request timeout? Feb 18, 2024 pm 01:58 PM

The HTTP request times out, and the server often returns the 504GatewayTimeout status code. This status code indicates that when the server executes a request, it still fails to obtain the resources required for the request or complete the processing of the request after a period of time. It is a status code of the 5xx series, which indicates that the server has encountered a temporary problem or overload, resulting in the inability to correctly handle the client's request. In the HTTP protocol, various status codes have specific meanings and uses, and the 504 status code is used to indicate request timeout issues. in customer

Combination of Golang and front-end technology: explore how Golang plays a role in the front-end field Combination of Golang and front-end technology: explore how Golang plays a role in the front-end field Mar 19, 2024 pm 06:15 PM

Combination of Golang and front-end technology: To explore how Golang plays a role in the front-end field, specific code examples are needed. With the rapid development of the Internet and mobile applications, front-end technology has become increasingly important. In this field, Golang, as a powerful back-end programming language, can also play an important role. This article will explore how Golang is combined with front-end technology and demonstrate its potential in the front-end field through specific code examples. The role of Golang in the front-end field is as an efficient, concise and easy-to-learn

How to implement h5 to slide up on the web side to load the next page How to implement h5 to slide up on the web side to load the next page Mar 11, 2024 am 10:26 AM

Implementation steps: 1. Monitor the scroll event of the page; 2. Determine whether the page has scrolled to the bottom; 3. Load the next page of data; 4. Update the page scroll position.

See all articles