Nginx set HTTPS without www to jump to https address with www

Source: Internet
Author: User
Tags certbot letsencrypt

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

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.