Nginx重写和proxy_pass说明

时间:2020-07-17 15:33:11

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

我可以在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; 是否已执行?

如果是,什么时候?

他们有什么意义?

1 个答案:

答案 0 :(得分:1)

如果该重写规则具有break标志而不是last,它将在将其传递给上游之前从/STFlow URI中删除/STFlow/some/path前缀。 e。除了设置locationdebug-header变量外,其他操作与第二个$realip块相同。但是据我所知,使用last标志使从未执行过四行,第二个location块内部将进行进一步的URI处理。