Nginx http and HTTPS (SSL) coexistence configuration method

Source: Internet
Author: User

Because the company project has to use the link to HTTPS, to get a certificate, after configuration, HTTPS can be normal access, but the previous HTTP is a 400 error, nginx configuration is as follows:

The code is as follows Copy Code

server {
Listen default backlog=2048;
Listen 443;
server_name 111cn.net;
root/var/www/html;

SSL on;
SSL_CERTIFICATE/USR/LOCAL/TENGINE/SSLCRT/111CN.NET.CRT;
Ssl_certificate_key/usr/local/tengine/sslcrt/111cn.net.key;
}

When HTTP is accessed, the error is as follows:

Bad Request
The plain HTTP Requset is sent to HTTPS port. Sorry for the inconvenience.
Please and include the following information to us.
Thank you very much!

It is said that the HTTP request was sent to the HTTPS port, which is why this problem occurs. Then this is not very pit,,, I just part of the need for HTTPS, but in this way, the HTTP link can not be used, and then the query data to adjust the configuration file as follows:

  code is as follows copy code

Server {
             Listen default backlog=2048;
            listen 443 SSL;
            server_name 111cn.net;
            root/var/www/html;

            ssl_certificate/usr/local/tengine/sslcrt/ 111CN.NET.CRT;
            ssl_certificate_key/usr/local/tengine/ Sslcrt/111cn.net.key;
}

Put SSL on; this line is removed and SSL is written behind port 443. So that the HTTP and HTTPS links can be used, the perfect solution.

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.