IT俱乐部 Nginx nginx proxy_redirect的作用及说明

nginx proxy_redirect的作用及说明

准备环境

springboot /redirect controller

curl http://localhost:10080/redirect -vv
*   Trying ::1:10080...
* Connected to localhost (::1) port 10080 (#0)
> GET /redirect HTTP/1.1
> Host: localhost:10080
> User-Agent: curl/7.76.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse

1. 默认配置

即proxy_redirect default;

location / {
                proxy_pass http://localhost:10080/;
        }

效果

curl -vv http://localhost/redirect
*   Trying ::1:80...
* connect to ::1 port 80 failed: 拒绝连接
*   Trying 127.0.0.1:80...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /redirect HTTP/1.1
> Host: localhost
> User-Agent: curl/7.76.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse

2. proxy_redirect default;

location / {
                proxy_pass http://localhost:10080/;
                proxy_redirect default;
        }

注意,proxy_redirect default必须在proxy_pass下方配置

效果

curl -vv http://localhost/redirect
*   Trying ::1:80...
* connect to ::1 port 80 failed: 拒绝连接
*   Trying 127.0.0.1:80...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /redirect HTTP/1.1
> Host: localhost
> User-Agent: curl/7.76.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse

与方案1等同

3. proxy_redirect off;

location / {
                proxy_pass http://localhost:10080/;
                proxy_redirect off;
        }

效果

curl http://localhost:10080/redirect -vv
*   Trying ::1:10080...
* Connected to localhost (::1) port 10080 (#0)
> GET /redirect HTTP/1.1
> Host: localhost:10080
> User-Agent: curl/7.76.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse

可以看到,302响应的是内部地址。

总结

常规部署情况下,不需要特别配置proxy_redirect或者配置proxy_redirect default即可。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持IT俱乐部。

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/server/nginx/12073.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部