转载自 Nginx报错“The plain HTTP request was sent to HTTPS port”问题解决办法
报错图片(宝塔的nginx报错)


解决方式

server {
listen 80;
listen 443 ssl;
server_name rel.whyrkj.net;
ssl_certificate cert/2444819_ren.whyrkj.net.pem;
ssl_certificate_key cert/2444819_ren.whyrkj.net.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location ~/
{
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}
实现流程是根据nginx的不同执行阶段,来完成Location http到https。
1)proxy_pass执行前,先设置了request head host 为https外网访问的域名+端口
2)proxy_pass执行后,tomcat结果返回response
3)proxy_redirect修改response中的location中的协议http为https外网访问的协议。
注:java redirect重定向主要是通过访问tomcat服务的请求head项来决定的,默认是http协议,域名是通过读取host地址,默认host中不包括访问端口。

15万+

被折叠的 条评论
为什么被折叠?



