nginx The plain HTTP request was sent to HTTPS port
时间: 2023-11-01 12:50:36 浏览: 117
Nginx出现The plain HTTP request was sent to HTTPS port问题解决方法
当使用nginx部署前端应用并将http访问转为https访问时,有时会出现"The plain HTTP request was sent to HTTPS port"的错误页面。这个错误的原因是客户端发送了一个普通的HTTP请求到了配置为HTTPS监听的端口上。解决这个问题的思路是将http的请求重定向到https。可以在nginx的配置文件中添加以下代码来实现重定向:
```
server {
listen 80;
listen 443 ssl;
ssl_certificate ssl_cert.pem;
ssl_certificate_key ssl_server.key;
server_name your_domain.com;
if ($scheme = http) {
return 301 https://$host$uri?$args;
}
location / {
....
}
}
```
这样配置后,当客户端发送http请求时,nginx会自动将其重定向到https,从而解决"The plain HTTP request was sent to HTTPS port"的错误页面问题。
阅读全文