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)

奋力向前
Release: 2021-09-01 11:09:18
forward
6256 people have browsed it

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

wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
Copy after login

automatically associate to

nginx
$sudo ./certbot-auto --nginx
```sh

## 检查证书有没有过期
Copy after login

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

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

```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

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

Okay, now open

nginxConfiguration and take a look

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

[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.

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

Next execute

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

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!

Related labels:
source:chuchur.com
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template