Nginx occurs with The plain HTTP request was sent to HTTPS port problem solving
- 2020-05-09 19:53:53
- OfStack
Today in the configuration of Nginx + SSL when there is such as the problem of the error, and later baidu 1 after the rain to find a solution, very useful, conveniently.
1 in vhost configuration, there will be a segment of php parsed, such as:
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;
}
Explanation:
Many people think fastcgi_param HTTPS on;
This is true, but forcing this parameter is not very effective!
The best answer is fastcgi_param HTTPS $https if_not_empty; (see nginx's official link below), https on is only automatically used when the https protocol is in place, otherwise fastcgi_param HTTPS parameter is ignored.
Inline variables:
The $https wok returns "ON" if the link is SSL, otherwise returns an empty string.
if_not_empty; The wok is passed to the server when the parameter has a value
Note: this method is only suitable for Nginx versions after 1.1.11
Reference:
stackoverflow/nginx#1/nginx#2