nginx反向代理 301跟随

53次阅读

共计 751 个字符,预计需要花费 2 分钟才能阅读完成。

用 nginx 反向代理 gravatar.com,域名用的是 gra-nl.abc.com
如果访问 https://gra-nl.abc.com/avatar/2b10d848378ffbfb5fc48020bf292378
可以正常返回头像,
但是如果访问
https://gra-nl.abc.com,反向代理的 http://gravatar.com 发来了一个 301 到 http://en.gravatar.com,nginx 把 301 又发给了访客
导致访客直接跳到了 http://en.gravatar.com
有没有办法不让他跳转呢(让 nginx 跟随 301,不把 301 发给访客

以前遇到过类似的问题,直接解决 301 跟随的话,可以这样:
server {
location / {
proxy_pass https://gravatar.com;
proxy_intercept_errors on;
error_page 301 302 307 = @handle_redirect;
}
location @handle_redirect {
set $saved_redirect_location ‘$upstream_http_location’;
proxy_pass $saved_redirect_location;
}
}复制代码
但是楼主也可以尝试下 proxy_redirect 替换 301 跳转中的 location 字段 http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect 说起来,我签名论坛里面的头像设计,也是基于用户名 / 用户 id 产生的一套,是根据一个开源前端项目改的,变成后端渲染 svg 的项目了

正文完
 0