nginx 反向代理设置中的proxy_redirect
2017-10-22 19:33
288 查看
Nginx做反向代理,如果在header设置了Host参数,同时如果有协议和二级目录有不一致的情况的时候,
当后端服务做302、301跳转的时候,需要用proxy_redirect将后端设置在response header中的Location做转换.
比如后端应用Java:
LOG.debug("sendRedirect host in header " + req.getHeader("Host"));
response.sendRedirect("t2");
1,浏览器通过https + 域名请求后端 http应用
通过nginx的域名访问:https://www.xxx.com.cn/test/trd
默认配置的情况下:
server {
listen 443;
ssl on;
server_name www.xxx.com.cn;
location /test/ {
proxy_pass http://10.65.192.xx:8080/; }
}
后端Java执行的情况为
LOG.debug("sendRedirect host in header " + req.getHeader("Host")); //10.65.192.xx:8080
response.sendRedirect("t2"); //http://10.65.192.xx:8080/t2
不需要设置proxy_redirect,nginx会将http://10.65.192.xx:8080/t2转成https://www.xxx.com.cn/test/t2
2,如果在header设置了Host参数:proxy_set_header Host $host;
LOG.debug("sendRedirect host in header " + req.getHeader("Host")); //www.xxx.com.cn
response.sendRedirect("t2"); //http://www.xxx.com.cn/t2
nginx需要配置proxy_redirect
server {
listen 443;
ssl on;
server_name www.xxx.com.cn;
location /test/ {
proxy_pass http://10.65.192.xx:8080/; proxy_redirect http://$host/ https://$host:$server_port/test/;
}
}
3.proxy_redirect 可以支持正则表达式,可以设置多个 proxy_redirect
当后端服务做302、301跳转的时候,需要用proxy_redirect将后端设置在response header中的Location做转换.
比如后端应用Java:
LOG.debug("sendRedirect host in header " + req.getHeader("Host"));
response.sendRedirect("t2");
1,浏览器通过https + 域名请求后端 http应用
通过nginx的域名访问:https://www.xxx.com.cn/test/trd
默认配置的情况下:
server {
listen 443;
ssl on;
server_name www.xxx.com.cn;
location /test/ {
proxy_pass http://10.65.192.xx:8080/; }
}
后端Java执行的情况为
LOG.debug("sendRedirect host in header " + req.getHeader("Host")); //10.65.192.xx:8080
response.sendRedirect("t2"); //http://10.65.192.xx:8080/t2
不需要设置proxy_redirect,nginx会将http://10.65.192.xx:8080/t2转成https://www.xxx.com.cn/test/t2
2,如果在header设置了Host参数:proxy_set_header Host $host;
LOG.debug("sendRedirect host in header " + req.getHeader("Host")); //www.xxx.com.cn
response.sendRedirect("t2"); //http://www.xxx.com.cn/t2
nginx需要配置proxy_redirect
server {
listen 443;
ssl on;
server_name www.xxx.com.cn;
location /test/ {
proxy_pass http://10.65.192.xx:8080/; proxy_redirect http://$host/ https://$host:$server_port/test/;
}
}
3.proxy_redirect 可以支持正则表达式,可以设置多个 proxy_redirect
相关文章推荐
- nginx反向代理设置
- Nginx 反向代理设置
- Nginx基础入门之proxy反向代理常用配置项说明
- nginx反向代理时,X-Forwarded-For 如何设置
- nginx 反向代理 端口设置问题
- nginx 安装+反向代理设置
- Nginx不同域名反向代理到另一台服务器 proxy_pass和$host
- 在Nginx服务器中配置mod_proxy反向代理的方法
- nginx反向代理proxy_set_header自定义header头无效
- 解决nginx使用proxy_pass反向代理时,cookie丢失的问题
- Nginx反向代理proxy_store配置
- nginx 安装+反向代理设置
- nginx设置反向代理后,页面上的js css文件无法加载
- Nginx前端设置反向代理,后端Apache如何获取访客的真实IP,结合PHP
- Nginx 反向代理设置
- nginx反向代理时,X-Forwarded-For 如何设置
- Nginx、haproxy反向代理设置
- nginx反向代理tomcat集群达到负载均衡,同时使用proxy_cache做web缓存 推荐
- Windows下Nginx学习历程_Nginx反向代理设置从80端口转向其他端口
- nginx反向代理proxy_set_header自定义header头无效的问题