Nginx appears the plain HTTP request is sent to HTTPS Port problem resolution _nginx

Source: Internet
Author: User

Today in the configuration of the Nginx+ssl when the title of the mistake, and later with the Niang a bit of sex after finding a solution, quite useful, conveniently turned.

Generally in the configuration of Vhost will have PHP parsing a paragraph, such as:

Copy Code code as follows:

Location ~. *\. (PHP|PHP5)? $
{
Try_files $uri = 404;
Fastcgi_pass Unix:/tmp/php-cgi.sock;
Fastcgi_param HTTPS $https If_not_empty;
Fastcgi_index index.php;
Include fcgi.conf;
}

Explain:

Many people think that using Fastcgi_param HTTPS on;

This is true, but forcing the use of this parameter is not very effective!

The best answer is Fastcgi_param HTTPS $https if_not_empty; (Refer to the official link below Nginx), the HTTPS protocol is used to automatically use HTTPS on, otherwise the Fastcgi_param HTTPS parameter is ignored.

Embedded variables:

$https – returns "on" if the link is SSL, otherwise an empty string is returned.

If_not_empty; – passed to the server when the parameter has a value

Note: This method is only suitable for versions after Nginx 1.1.11

Reference:
stackoverflow/nginx#1/nginx#2

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.