微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NGINX重写始终返回302

我完全被Nginx重写的行为所困扰.我有以下2个位置块 – 第一个只是重写,以便第二个被调用.

location /alt/digest/rewrite {
    rewrite /alt/digest/rewrite http://$server_name/digest/wms break;
}

location /digest/wms {
   ...
}

但是当我达到http://server_name/alt/digest/rewrite时,我总是在我的curl应用程序上得到以下内容

<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>Nginx/1.6.2</center>
</body>
</html>

任何帮助,将不胜感激.

解决方法:

这种行为实际上在rewrite documentation中有详细描述:

If a replacement string starts with “http://” or “https://”, the processing stops and the redirect is returned to a client.

删除方案和主机部分,然后重写为仅绝对路径.
也用last替换break:

last
stops processing the current set of ngx_http_rewrite_module directives and starts a search for a new location matching the changed URI;

rewrite /alt/digest/rewrite /digest/wms last;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐