解决nginx https代理tomcat redirect问题
来源:互联网 发布:网校用什么软件 编辑:程序博客网 时间:2024/06/05 08:54
原文:http://blog.csdn.net/juncke/article/details/52539175
问题描述
http服务器:nginx,10.10.10.95,版本:1.10.1,请求使用协议为https,端口为18080。
服务服务器:tomcat,10.10.10.92,使用协议为http,端口为8080。
问题:当在业务服务器使用sendRedirect时,tomcat响应302给nginx,nginx再响应给浏览器,默认情况下,nginx响应给浏览器的location会将schema换为http,端口为:80。
这就导致浏览器redirect后,访问不到正确资源。
过程举例:
- 浏览器输入:https://10.10.10.95:18080/redirect_test.do
- redirect_test.do中执行sendRedirect("/welcome.do")
- 浏览器接收到的redirect响应(302)中location为http://10.10.10.95/welcome.do
- 浏览器跳到http://10.10.10.95/welcome.do,发现访问不了
解决方案
修改nginx配置,关键配置如下:
server{
listen 18080;
server_name ecsc;
ssl on;
ssl_certificate /root/ssl/test.crt;
ssl_certificate_key /root/ssl/test_nopass.key;
error_page 497 https://$host:8080;
access_log /var/log/nginx/access.log main;
proxy_redirect http:// $scheme://;
port_in_redirect on;
location ~/druid{
return 404;
}
location /{
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
expires 10d;
proxy_pass http://console.eayun.com ;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
}
说明:
使用proxy_redirect将location中的协议转换为请求nginx的协议。
使用port_in_redirect on指示nginx使用请求的端口,而不是使用默认端口。
proxy_set_header Host $host:$server_port;很关键,我也不明白为啥,不设置,端口为变为80。
- 解决nginx https代理tomcat redirect问题
- 解决nginx https代理tomcat redirect问题
- nginx配置https代理tomcat
- 反向代理https后redirect出现问题
- SpringBoot+Nginx+Https下redirect问题
- nginx配置tomcat https websockets等问题汇总解决方式
- 解决Nginx+Tomcat中https转http请求问题
- nginx 代理https后,spring mvc web应用redirect https变成http
- 【Tomcat】-- Tomcat + Nginx反向代理https和wss并解决获取客户端真实IP、域名、协议、端口
- 解决Nginx+Tomcat下客户端https请求跳转成http的问题
- nginx反向代理tomcat的ssl(https)实现
- Nginx + 阿里云SSL + tomcat 实现https访问代理
- Nginx + 阿里云SSL + tomcat 实现https访问代理
- Nginx + 阿里云SSL + tomcat 实现https访问代理
- nginx反向代理多个tomcat 配置.解决因404问题js css无法加载问题
- nginx SSl redirect问题
- nginx下redirect问题
- nginx解决单点tomcat问题
- 处理JS分页加载的网页_recv
- c++学习笔记
- ubuntu eclipse CDT编译mysql源码
- Workerman
- 复数的抽象数据类型实现(指针)
- 解决nginx https代理tomcat redirect问题
- Linux查看系统信息的一些命令及查看已安装软件包的命令
- L26 grep和egrep工具的使用
- 【linux 学习】linux上安装mysql(linut mint)
- 【转载】M4
- MySQL操作表结构
- Reactor5.0源代码混淆器
- git报错-->! [remote rejected] master -> master (push declined due to email privacy restrictions)
- Javaweb项目搭建ehcache缓存系统