NutzCN Logo
问答 Mvcs.getResp().sendRedirect()只支持 http 的跳转么?
发布于 3104天前 作者 ywjno 2342 次浏览 复制 上一个帖子 下一个帖子
标签:

网站部署在 https 下,但是 Mvcs.getResp().sendRedirect("/errors/404.html") 它给跳转到了 http 的路径下以至于页面无法显示

8 回复

在nginx的proxy_pass下面加入这个

proxy_redirect http:// https://;

本站就是这样配置, 执行curl可以检测

root@AY1401171939223973beZ:/opt/openresty/nginx# curl -I https://nutz.cn/home
HTTP/1.1 302 Found
Server: nginx/1.9.5
Date: Tue, 27 Oct 2015 01:57:21 GMT
Connection: keep-alive
Location: https://nutz.cn/user/login

原因并非nutz支持与否,是tomcat/jetty不知道自己在https地址的后面

这是直接访问8080端口的输出, 可以看到并没有https

root@AY1401171939223973beZ:/opt/openresty/nginx# curl -I -H "Host: nutz.cn" http://127.0.0.1:8080/home
HTTP/1.1 302 Found
Date: Tue, 27 Oct 2015 01:59:29 GMT
Location: http://nutz.cn/user/login
Content-Length: 0
Server: Jetty(9.3.5.v20151012)

PS, 只能写一个哦, 例如下面这种就非常坑爹

proxy_redirect http:// https://;
proxy_redirect off;

类似有这种情况:

@At("login")
login(){
	return new ServerRedirectView("/index");
}

当请求login时,这种从内部跳转没有经过客户端过去的index,没有经过nginx,会出现301 Moved Permanently
按照wiki上的说法:

如果是除了 GET 和 HEAD 之外的请求方法,客户端必须在重定向之前询问用户。

这种没有询问用户的请求,该如何处理

类似的有很多这种:

@At("login")
@Ok("redirect:/index")
public void login(){
//
}

ServerRedirectView不是内部跳转. ForwardView才是内部跳转.

ServerRedirectView 会响应为302 (会经过nginx,受proxy_redirect控制), 然后客户端再发起一个新请求.

另外, 不知道你说的wiki "如果是除了 GET 和 HEAD 之外的请求方法,客户端必须在重定向之前询问用户" 是什么玩意.

添加回复
请先登陆
回到顶部