Home > Article > Web Front-end > Teach you step by step how to enable https and http2 for your site (with code)
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.
This article mainly introduces how to enable https
and http2
# for the site
##This article mainly introduces how to enablehttps and
http2
https for the site. Simply take this site
Linux nginx as an example
wget https://dl.eff.org/certbot-auto chmod a+x certbot-auto
$sudo ./certbot-auto --nginx ```sh ## 检查证书有没有过期
$sudo ./certbot-auto renew --dry-run
## 如果过期了就自动续订 ```sh $sudo ./certbot-auto renew
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
grep -r -P '[^\x00-\x7f]' /etc/nginx /etc/letsencryptOkay, 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
Note that the nginx version is too low If it cannot be opened, you must first upgrade the nginx version, taking centos as an exampleModify 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
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 stop
killall nginx, then uninstall
yum remove nginx and then reinstall
yum install nginx
Ubuntu/Debian upgrade HTTP/2
First modifyaptwarehouse 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 nginxNext execute
apt-get clean && apt-get install nginxOkay, now the
https is successfully opened,
443 ssl The one behind
http2, that is, it is turned on
http2
nginx -s reloadRefresh the page and find a lock in front of the URL, which means
https is successfully opened
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
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!