【问题标题】:Nginx rewrite and proxy_pass explanationNginx rewrite和proxy_pass解释
【发布时间】:2020-11-07 10:50:50
【问题描述】:

我可以在 nginx/okd 配置中看到以下位置:

    location /STFlow/ {
        rewrite ^/STFlow(.*)$ $1 last;
#   
#          Are four lines below executed if rewrite has last option ???
#          What's the point of them?          
#
        proxy_pass http://zuul-proxy:8080; 
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $http_x_forwarded_for;
        proxy_set_header X-Forwarded-For $http_x_forwarded_for;
    }

    location / {
        add_header debug-header dbg5;   
        set $realip $remote_addr;
        if ($http_x_forwarded_for ~ "^(\d+\.\d+\.\d+\.\d+)") {
            set $realip $1;
        }
        proxy_pass http://zuul-proxy:8080; 
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $http_x_forwarded_for;
        proxy_set_header X-Forwarded-For $http_x_forwarded_for;
        client_max_body_size 50M;
    }

location /STFlow/下面有四行rewrite ^/STFlow(.*)$ $1 last;执行过吗?

如果是什么时候?

它们的意义何在?

【问题讨论】:

    标签: nginx nginx-reverse-proxy nginx-location nginx-config nginx-ingress


    【解决方案1】:

    如果重写规则有一个break 标志而不是last,它会在将/STFlow/some/path URI 传递给上游之前删除/STFlow 前缀,即。 e.除了设置debug-header$realip 变量外,与第二个location 块相同。但据我了解,使用 last 标志会使这四行永远不会执行,进一步的 URI 处理将在第二个 location 块内完成。

    【讨论】:

    • 在我看来也是这样,但是我是 nginx 和 okd 的新手,这是我第一次接触它,并且必须对现有配置进行一些更改。
    • @bastiat 大多数看起来有人打算使用break 标志,但偶尔会犯错误。
    猜你喜欢
    • 2019-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-08
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多