How to Configure nginx to access http to automatically redirect to https

Source: Internet
Author: User
Tags ssl certificate

I applied for a two-year ssl certificate at wosign last night and deployed it soon.

Today, I configured it to automatically redirect the http url to https.

The configuration is as follows:


Listen 80;
Listen 443 ssl;
Ssl_certificate/PATH_TO_CRT;
Ssl_certificate_key/PATH_TO_KEY;
Server_name upliu.net;
If ($ scheme! = Https ){
Rewrite ^/(. *) https: // $ server_name/$1 permanent;
}

Listen to ports 80 and 443 at the same time, and add ssl support to ports 443. If the access is not over https, it is redirected to the https path.

Example

Server {
Server_name www.111cn.net;
Location = /{
Rewrite ^ https: // www.111cn.net redirect;
        }

}

Example

302 redirect settings:

Server {
Listen 80;
Server_name 111cn.net;
Rewrite ^/(. *) https: // www.111cn.net/#1 redirect;
Access_log off;
}

 

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.