Once the domain name has been added to the certificate, we generally want to redirect all requests to a URL, so that when the search engine in the crawl can be centralized in an address, in favor of SEO
Such as:
We want the following three domains to be redirected to Https://www.xiaoben707.com
Http://www.xiaoben707.com
Http://xiaoben707.com
Https://xiaoben707.com
We need to do the following two settings in Nginx:
First:
server {Listen 80;server_name xiaoben707.com www.xiaoben707.com;return 301 Https://www.xiaoben707.com$request_uri;}
This means simple, permanently redirecting 80 ports of xiaoben707.com and www.xiaoben707.com to https://www.xiaoben707.com
Second:
server {
Listen 443;
server_name xiaoben707.com;
return 301 Https://www.xiaoben707.com$request_uri;
SSL_CERTIFICATE/ETC/LETSENCRYPT/LIVE/XIAOBEN707.COM/FULLCHAIN.PEM; # Managed by Certbot
SSL_CERTIFICATE_KEY/ETC/LETSENCRYPT/LIVE/XIAOBEN707.COM/PRIVKEY.PEM; # Managed by Certbot
}
Here is the https://xiaoben707.com redirect to Https://www.xiaoben707.com, it is worth noting, here also need xiaoben707.com certificate. I usually generate directly with Certbot.
Nginx set HTTPS without www to jump to https address with www