Nginx反向代理https报错The plain HTTP request was sent to HTTPS port解决办法
时间: 2023-12-01 18:43:25 浏览: 178
为了解决Nginx反向代理https报错“The plain HTTP request was sent to HTTPS port”的问题,可以按照以下步骤进行操作:
1.在Nginx配置文件中添加以下代码:
```nginx
server {
listen 80;
server_name yourdomain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name yourdomain.com;
ssl_certificate /path/to/your/cert.pem;
ssl_certificate_key /path/to/your/key.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
location / {
proxy_pass https://yourbackend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
```
2.将上述代码中的“yourdomain.com”替换为你的域名,将“/path/to/your/cert.pem”和“/path/to/your/key.pem”替换为你的SSL证书和密钥的路径,将“yourbackend”替换为你的后端服务器地址。
3.重新加载Nginx配置文件,使其生效。
通过以上步骤,就可以解决Nginx反向代理https报错“The plain HTTP request was sent to HTTPS port”的问题。
阅读全文